﻿var zoomsum = 0; var widthlocal = 0; var heightlocal = 0;
var idjm = false; var programtype = 0;

//选择图片
window.loadImg = function (obj) {
  $(obj).parent().find(".upload_input").click();
}
//删除
window.deleteImg = function (obj) {
  if (confirm("是否删除图片")) {
    //alert($(obj).parent().index());
    $(obj).parent().find('input').eq(0).val('');
    $(obj).parent().find('.preview').html('');
    $(obj).hide();
    $(obj).parent().find('#pathimg').eq(0).val('');
    imgfile[$(obj).parent().find('#hfile1').val()] = "";
    //imgfile.splice($(obj).parent().index(),1);
    //console.log(imgfile);
    // $("#program_"+selectid).find("img").eq($(obj).parent().index()).remove();
    $("#imgadd_" + $(obj).parent().find('#hfile1').val()).remove();
  }
}
window.deleteImggif = function (obj) {
  if (confirm("是否删除动画")) {
    $(obj).parent().find('input').eq(0).val('');
    $(obj).parent().find('.preview').html('');
    $(obj).hide();
    $(obj).parent().find('#pathimggif').eq(0).val('');
    imgfilegif[$(obj).parent().find('#hfile2').val()] = "";
    //imgfile.splice($(obj).parent().index(),1);
    //console.log(imgfile);
    // $("#program_"+selectid).find("img").eq($(obj).parent().index()).remove();

    $("#imgaddgif_" + $(obj).parent().find('#hfile2').val()).remove();
    // $("#program_"+selectid).find("img").eq($(obj).parent().index()).remove();
  }
}
var prevFile = null;
var imgfile = new Array(); var imgfilegif = new Array();
//var imgfilelist=new Array();
window.preview = function (file) {

  var suffix = file.files[0].name.split('.');
  if (!/(jpg|jpeg)$/.test(suffix)) {
    swal("OMG!", "图片格式不正确，请重新上传", "error");
    return false;
  }
  var fla = true;

  var AllowImgFileSize = 5120;  //最大5M
  var imgsize = file.files[0].size / 1024;
  console.log("大小：" + imgsize)
  if (AllowImgFileSize != 0 && AllowImgFileSize < imgsize) {
    swal("OMG!", "图片大小不超过5M，请重新选择", "error");
    return false;
  }

  var file2 = file.files[0] || imgfile[$(file).parent().find("#hfile1").val()];
  if (!file2) return false;
  ///此处省略一大段逻辑///
  prevFile = file2;
  imgfile[$(file).parent().find("#hfile1").val()] = file2;
  var prevDiv = $(file).parent().find('.preview');

  //
  // alert($(file).val());
  //$(file).parent().find('.delete').hide();
  var sele = "";

  if (file.files && file.files[0]) {
    sele = "1";
    var reader = new FileReader();
    reader.onload = function (evt) {

      //删除原来的




      //photoCompress
      //console.log(file.files[0]);
      var image = new Image();
      image.src = evt.target.result;
      image.onload = function () {
        var width = this.width;
        var height = this.height;
        var width1 = $("#from_" + selectid).find("#width").val();
        var height1 = $("#from_" + selectid).find("#high").val();
        // alert(height1); alert(width1);

        if (parseInt(height) > parseInt(height1) || parseInt(width) > parseInt(width1)) {
          console.log("jinlaihh")
          swal("OMG!", "选择动画图片不能超过分区宽高,图片尺寸为：" + width + "*" + height, "error");
          $(file).parent().find('.delete').hide();
          $(file).val("");
          return;

        }
        $("#program_" + selectid).find("#imgadd_" + $(file).parent().find("#hfile1").val()).remove();
        $("#program_" + selectid).append("<img  id=imgadd_" + $(file).parent().find("#hfile1").val() + " src='" + evt.target.result + "'  class='img-rounded' style=height:" + 100 + "%;width:" + 100 + "%;>");
        prevDiv.html('<img src="' + evt.target.result + '" />');
        canvasDataURL(evt.target.result, this.width, $("#imgadd_" + $(file).parent().find("#hfile1").val()))
        //alert(width+'======'+height+"=====");     
      };
    }
    reader.readAsDataURL(file.files[0]);

    var formData = new FormData();
    formData.append('file', file.files[0]);
    // if(fla==false){

    //   return false;
    // }
    $.fn.jqLoading({ height: 100, width: 240, text: "图片上传中，请耐心等待...." });

    $.ajax({
      url: domain.testUrl + "/Threeinjection/programManagement/FTPupload?coId=" + sessionStorage.getItem("coid"),
      type: 'POST',
      cache: false,
      data: formData,
      processData: false,
      contentType: false
    }).done(function (res) {
      // alert(res);
      // logo=res;
      //res=logo;
      //pathimggif
      $.fn.jqLoading("destroy");

      res = JSON.parse(res);
      $(file).parent().find("#pathimg").val(res.data);



      var pathsize = file.files[0].size / 1024;
      $(file).parent().find("#pathsize").val(parseInt(pathsize));

      //console.log(res);
      try {
        $(file).parent().find("#fileId").val(res.fileId);
      } catch (ex) {

      }

    }).fail(function (res) {
    });
  } else {//IE
    //prevDiv.html('<div class="img" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src=\'' + file.value + '\'"></div>');
  }
  $(file).parent().find('.delete').show();
}
window.previewgif = function (file) {

  var suffix = file.files[0].name.split('.');
  if (!/(gif)$/.test(suffix)) {
    swal("OMG!", "gif格式不正确，请重新上传", "error");
    return false;
  }
  //判断大小
  var AllowImgFileSize = 5120;  //最大5M
  var gifsize = file.files[0].size / 1024;
  console.log("大小：" + gifsize)
  if (AllowImgFileSize != 0 && AllowImgFileSize < gifsize) {
    swal("OMG!", "gif大小不超过5M，请重新选择", "error");
    return false;
  }

  var file2 = file.files[0] || imgfilegif[$(file).parent().find("#hfile2").val()];
  if (!file2) return false;
  ///此处省略一大段逻辑///
  prevFile = file2;

  imgfilegif[$(file).parent().find("#hfile2").val()] = file2;

  var prevDiv = $(file).parent().find('.preview');


  //
  // alert($(file).val());
  //$(file).parent().find('.delete').hide();
  var sele = "";
  if (file.files && file.files[0]) {
    sele = "1";
    var reader = new FileReader();
    //  var image = new Image();
    reader.onload = function (evt) {
      //加载图片获取图片真实宽度和高度
      var image = new Image();
      image.src = evt.target.result;
      image.onload = function () {
        var width = image.width;
        var height = image.height;
        var width1 = $("#from_" + selectid).find("#width").val();
        var height1 = $("#from_" + selectid).find("#high").val();
        // alert(height1); alert(width1);

        $("#gifwidepth").val(width + "*" + height);
        if (parseInt(height) > parseInt(height1) || parseInt(width) > parseInt(width1)) {
          // 隐藏
          swal("OMG!", "选择动画图片不能超过分区宽高,动画尺寸为：" + width + "*" + height, "error");
          $(file).val("");
          return;

        }




        prevDiv.html('<img src="' + evt.target.result + '" />');
        $("#program_" + selectid).find("#imgaddgif_" + $(file).parent().find("#hfile2").val()).remove();


        $("#program_" + selectid).append("<img  id=imgaddgif_" + $(file).parent().find("#hfile2").val() + " src='" + evt.target.result + "'  class='img-rounded' style=height:" + 100 + "%;width:" + 100 + "%;>");

        //gif预览
        gifwg(selectid);
        var formData = new FormData();
        formData.append('file', file.files[0]);
        $.fn.jqLoading({ height: 100, width: 240, text: "gif上传中，请耐心等待...." });
        $.ajax({
          url: domain.testUrl + "/Threeinjection/programManagement/FTPupload?coId=" + sessionStorage.getItem("coid"),
          type: 'POST',
          cache: false,
          data: formData,
          processData: false,
          contentType: false
        }).done(function (res) {


          $.fn.jqLoading("destroy");
          // logo=res;
          //res=logo;
          //pathimggif
          res = JSON.parse(res);
          $(file).parent().find("#pathimggif").val(res.data);
          var pathsize = file.files[0].size / 1024;
          $(file).parent().find("#pathgifsize").val(parseInt(pathsize));
          //console.log(res);
          try {
            $(file).parent().find("#fileId").val(res.fileId);
          } catch (ex) {

          }
        }).fail(function (res) {
        });
        $(file).parent().find('.delete').show();
      }
    };
    reader.readAsDataURL(file.files[0]);
  } else {//IE
    //prevDiv.html('<div class="img" style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src=\'' + file.value + '\'"></div>');
  }

}
//删除分区
window.del = function (thi) {

  $(thi).parent().parent().remove();
  //alert( $("#from_"+$(thi).parent().parent().attr("id")).parent().html());

  $("#from_" + $(thi).parent().parent().attr("id")).find(".item").each(function (i) {


    if ($(this).parent().parent().attr("id").toString() == "imgadd") {

      imgfilegif[$(this).find("#hfile1").val()] = "";
    }
  });
  //console.logconsole.log(imgfilegif);
  $("#from_" + $(thi).parent().parent().attr("id")).parent().remove();
  $("#program_" + $(thi).parent().parent().attr("id")).remove();
  if ($("#program").find("div").length == 0) {
    $(".panel-heading").click();
    // $("#splitscreen").css("height",420);
  } else {
    $("#material li").click();
  }

};


var selectid = "";//选择的分区
var programmax = 129;
window.canvas = function () {

  var c = document.getElementById("screen_size");

  var ctx = c.getContext("2d");
  ctx.canvas.width = ctx.canvas.width;
  var width = $("#program")[0].offsetWidth;
  var height = $("#program")[0].offsetHeight;
  // if(width>698 || height> 180) {
  //   $("#screen_size").attr("width",1).attr("height",1);
  // return;
  // }
  //$("#screen_size").css({"left":$("#program")[0].offsetLeft, "top": $("#program")[0].offsetTop});
  $("#screen_size").css({ "left": $("#program")[0].offsetLeft, "top": parseInt($("#program")[0].offsetTop) + 0 });

  $("#screen_size").attr("width", width + 20).attr("height", height + 20);

  //if(width>60) {
  ctx.moveTo(1, height + 5);
  ctx.lineTo(1, height + 15);
  ctx.moveTo(1, height + 10);
  ctx.lineTo(width / 2 - 20, height + 10);
  ctx.moveTo(width / 2 + 20, height + 10);
  ctx.lineTo(width, height + 10);
  ctx.moveTo(width, height + 5);
  ctx.lineTo(width, height + 15);
  // }

  if (height > 16) {
    ctx.moveTo(width + 5, 1);
    ctx.lineTo(width + 15, 1);
    ctx.moveTo(width + 10, 1);
    ctx.lineTo(width + 10, height / 2 - 10);
    ctx.moveTo(width + 10, height / 2 + 10);
    ctx.lineTo(width + 10, height);
    ctx.moveTo(width + 5, height);
    ctx.lineTo(width + 15, height);
  }

  ctx.strokeStyle = "red";
  ctx.stroke();
  var sw = sessionStorage.getItem("width");
  var sh = sessionStorage.getItem("high");
  ctx.fillStyle = 'rgba(255,0,0,1)';
  ctx.font = "13px arial";
  //  if(width>60) {
  ctx.fillText(sw, width / 2 - sw.length * 3, height + 14);
  ctx.save();
  // }
  //if(height>60) {
  ctx.rotate(-Math.PI / 2);
  ctx.fillText(sh, -height / 2 - sh.length * 3, width + 14);
  //  }
  ctx.restore();


};
//节目号
window.programlist = function () {
  $.ajax({
    type: "POST",
    url: domain.testUrl + "/Threeinjection/programManagement/queryPermissionInfo",
    data: { "companyId": sessionStorage.getItem("coid"), sessionid: sessionStorage.getItem("sid") },
    //视情况将base64的前面字符串data:image/png;base64,删除
    cache: false,
    success: function (response) {
      $("#programid").empty();
      var response = JSON.parse(response);
      // response.programEnd=10;
      var spprograid = response.programNumber.toString();
      spprograid = spprograid.split(",");
      for (var i = 1; i < programmax; i++) {
        var is = true;
        if (response.programNumber.length > 0) {
          var ii = i - 1;
          for (var j = 0; j < spprograid.length; j++) {
            if (spprograid[j] == ii) {
              $("#programid").append("<option disabled='disabled' style='color: ;'>" + i + "</option>");
              is = false;
            }
          }
        }
        if (is) {
          if (i > parseInt(response.programEnd)) {
            $("#programid").append("<option style='color:#44d607;'>" + i + "</option>");
          } else {

            $("#programid").append("<option disabled='disabled' style='color: ;'>" + i + "</option>");
          }
          $("#programid option:eq(126)").hide();

        }
      }
    }
  });
}
$(function () {

  //加载节目号
  programlist();
  var w = parseInt(sessionStorage.getItem("width"))
  var h = parseInt(sessionStorage.getItem("high"));

  if (w == 0 && h == 0) {
    swal("提示", "单位没有设置屏高，请到卡组里新增节目", "info")

  }

  $("#jwidth").val(parseInt(w));
  $("#jhigh").val(parseInt(h));

  //把时段时间设为00
  for (var i = 1; i <= 8; i++) {
    showTimer('liveStart' + i, 1);
    showTimer('liveEnd' + i, 1);

    $('#liveStart' + i).find("input:eq(0)").val("00");
    $('#liveStart' + i).find("input:eq(2)").val("00");
    $('#liveEnd' + i).find("input:eq(0)").val("00");
    $('#liveEnd' + i).find("input:eq(2)").val("00");
  
}


  

  //时段默认显示一个值
  setTimeout(function () {
    timeChange();
  }, 1000);

  $("#highTime").click(function () {
    if ($(this).is(":checked")) {
      $("#highTime").parent().next().show();
      $("#highTime").parent().next().css("display", "-webkit-inline-box");
      $("#liveCount").parent().show();
      $("#liveTime").parent().show();
    } else {
      $("#highTime").parent().next().hide();
      $("#liveCount").parent().hide();
      $("#liveTime").parent().hide();
    }
  });
  $("#devicetype").val(sessionStorage.getItem("type"));
  //单双色只有文本
  if ($("#devicetype").val() == "0" || $("#devicetype").val() == "1") {
    $("#materialinfo li:eq(1),#materialinfo li:eq(2)").hide()
    $("#Dazzle,#typefaceval").parent().hide();
  } else {
    $("#materialinfo li:eq(1),#materialinfo li:eq(2)").show();
    $("#Dazzle").parent().show();
  }

  //播放类型
  $("#playtype").change(function () {
    if ($(this).val() == "0") {

      $("#playtime").prev().text("次数");
    } else {
      $("#playtime").prev().text("时长(s)");
    }
  });

  //语音
  $("#isplayvoice").change(function () {
    if ($(this).val() == "1") {
      swal("温馨提示", "播放语音已开启，“节目名称”为播放的内容", "info");
    }
  });

  //节目播放次数
  for (var i = 1; i <= 23; i++) {
    if (i == 1) {
      $("#playtime").append("<option value='" + i + "' selected>" + i + "</option>");
    } else {
      $("#playtime").append("<option value='" + i + "'>" + i + "</option>");
    }

  }



  console.log("分辨率" + screen.width)
  if (screen.width < 1280) {
    // console.log("小于")
    $("div:first").css("width", "120%");
  }
  if (screen.width >= 1280) {
    //  console.log("大于")
    $("div:first").css("width", "");
  }



  //$("#program").css("height",$("#jhigh").val()+"px");
  //$("#program").css("width",$("#jwidth").val()+"px");

  $("#program").css("height", parseInt($("#jhigh").val()) + "px");
  $("#program").css("width", parseInt($("#jwidth").val()) + "px");


  setTimeout(function () {
    canvas();
    setTimeout(function () {
      //默认方法

      $("#zoom img").eq(0).click();


    }, 500);
  }, 200);
  $("#zoom img").eq(0).click(function () {
    //转四舍五入，转int的话，值可能会有问题，会少
    var width = Math.round($("#program").outerWidth()) * 2;
    var height = Math.round($("#program").outerHeight()) * 2;

    if (height > 192 || zoomsum == 2) {

      return false;
    }

    widthlocal = width;
    heightlocal = height;
    $("#zoom img").eq(1).show();

    zoomsum++;
    $("#zoomsum").text(zoomsum);
    $("#program").css("width", width);
    $("#program").css("height", height);
    //遍历所有分区
    $(".transparent_class").each(function (i) {
      $(".transparent_class").eq(i).css("width", parseInt($(".transparent_class").eq(i).css("width")) * 2);
      $(".transparent_class").eq(i).css("height", parseInt($(".transparent_class").eq(i).css("height")) * 2);
      //x和y轴移动
      if (parseInt($(".transparent_class").eq(i).css("left")) > 0) {
        //var left=parseInt(width)-parseInt($(".transparent_class").eq(i).css("width"));
        var left = parseInt($(".transparent_class").eq(i).css("left")) * 2;
        $(".transparent_class").eq(i).css("left", left);
      }
      if (parseInt($(".transparent_class").eq(i).css("top")) > 0) {
        //var left=parseInt(width)-parseInt($(".transparent_class").eq(i).css("width"));
        var top = parseInt($(".transparent_class").eq(i).css("top")) * 2;
        $(".transparent_class").eq(i).css("top", top);
      }
      var id = $(this).attr("id").split("_")[1]
      var reg = new RegExp("px", "g");
      var size = $('#from_' + id).find("#fontsizeadd").find("option:selected").text().replace(reg, "");
      size = size.split("*")[0];
      $("#program_" + id).css("font-size", size + "px");
      if (zoomsum > 0) {
        var zoomsumval = zoomsum * 2;
        zoomsumval = size * zoomsumval;
        $("#program_" + id).css("font-size", zoomsumval + "px");
      }
      //gif预览
      gifwg(id);
      //画布
     textcanvas(id);
    });
    //字体放大
    try {
      // Fontmax();
    } catch (ex) {
    }
    canvas();

    // alert(123);
  });
  $("#zoom img").eq(1).click(function () {
    var width = parseInt($("#program").css("width")) / 2;
    var height = parseInt($("#program").css("height")) / 2;
    if (zoomsum > 0) {
      zoomsum--;
      $("#zoomsum").text(zoomsum);
      if (zoomsum == 0) {
        $("#zoom img").eq(1).hide();
      }
    }
    if (height < 16) {

      return;
    }

    widthlocal = width;
    heightlocal = height;
    $("#program").css("width", width);
    $("#program").css("height", height);

    //遍历所有分区
    $(".transparent_class").each(function (i) {

      $(".transparent_class").eq(i).css("width", parseInt($(".transparent_class").eq(i).css("width")) / 2);
      $(".transparent_class").eq(i).css("height", parseInt($(".transparent_class").eq(i).css("height")) / 2);
      //x和y轴移动
      if (parseInt($(".transparent_class").eq(i).css("left")) > 0) {
        //var left=parseInt(width)-parseInt($(".transparent_class").eq(i).css("width"));
        var left = parseInt($(".transparent_class").eq(i).css("left")) / 2;


        $(".transparent_class").eq(i).css("left", left);
      }

      if (parseInt($(".transparent_class").eq(i).css("top")) > 0) {
        //var left=parseInt(width)-parseInt($(".transparent_class").eq(i).css("width"));
        var top = parseInt($(".transparent_class").eq(i).css("top")) / 2;
        $(".transparent_class").eq(i).css("top", top);
      }

      var id = $(this).attr("id").split("_")[1]
      var reg = new RegExp("px", "g");
      var size = $('#from_' + id).find("#fontsizeadd").find("option:selected").text().replace(reg, "");
      size = size.split("*")[0];
      $("#program_" + id).css("font-size", size + "px");
      if (zoomsum > 0) {
        var zoomsumval = zoomsum * 2; zoomsumval = size * zoomsumval;
        $("#program_" + id).css("font-size", zoomsumval + "px");
      }
      //gif预览
      gifwg(id);
      //画布
      textcanvas(id);
    });

    //字体放大
    try {
      // Fontmax();
    } catch (ex) {

    }



    canvas();

    //  alert(456);
  });
 $('.time').clockTimePicker({});
  var myDate = new Date();
  //var time = myDate.toLocaleDateString().split('/').join('-');
  var date = new Date();
  var y = date.getFullYear();
  var m = date.getMonth() + 1;
  var d = date.getDate();
  var day = date.getDay();
  $("#starttime").val(y + "-" + m + "-" + d);
  $("#starttime").val("2012-01-01");
  // myDate = new Date(myDate.getTime()+24*60*60*1000);
  //time = myDate.toLocaleDateString().split('/').join('-');
  //$("#endtime").val("2099-12-30");

  $("#endtime").val("2035-12-30");

  //开始时间段
  $("#timeid").val("00:00");
  //结束
  $("#starthour").val("23:59");

  //for ( var i = 0; i < 24; i++)
  //  {
  //var opt = document.getElementById("timeid");
  //	  var min = document.getElementById("starthour");
  // $("#timeid,#starthour").append("<option id="+i+">"+i+""+"</option>");
  //}

  //swal({ 
  //   title: "您确定要吗？",  
  // text: "您确定要删除这条数据？",  
  //   type: "warning", 
  //   showCancelButton: true, 
  //  closeOnConfirm: false, 
  //  confirmButtonText: "是的，我要删除", 
  //  confirmButtonColor: "#ec6c62" 
  //  }, function() { 
  // $.ajax({ 
  //  url: "do.php", 
  // type: "DELETE" 
  //  }).done(function(data) { 
  //  swal("操作成功!", "已成功删除数据！", "success"); 
  //  }).error(function(data) { 
  //  swal("OMG", "删除操作失败了!", "error"); 
  //  }); 
  //  }); 






  	//$("#timeid,#starthour").hunterTimePicker();



  $('.spinner .btn:first-of-type').eq(6).on('click', function () {

    $('#jwidth').val(parseInt($('#jwidth').val()) + 8);

    $("#program").css("width", $("#jwidth").val());
    //console.log($("#program div").css("left"));
    $("#program div").each(function () {
      var reg = new RegExp("px", "g");
      if (parseInt($("#jwidth").val()) < parseInt($(this).css("width"))) {
        $("#program").css("width", $(this).css("width"));
        $('#jwidth').val($(this).css("width").replace(reg, ""));
      }
    });

    setTimeout(function (i) {
      $("#program div").each(function (i) {
        var reg = new RegExp("px", "g");
        // console.log($("#program").css("margin-left"));
        //$(this).css("left",'');
        // $(this).find("#leftdw").val($(this).css("left").replace(reg, ""));
        // i=i+1;

        //$(".col-md-9").find(".form-inline").find("#left").val(0);

      }), 100
    });

  });
  $('.spinner .btn:last-of-type').eq(6).on('click', function () {
    //  $('.spinner input').val( parseInt($('.spinner input').val(), 10) - 8);  
    //$('#jwidth').val(parseInt($('#jwidth').val()) + 8);  
    var value = parseInt($('#jwidth').val()) - 8;
    if (value < 0) {
      return;
    }
    $('#jwidth').val(parseInt($('#jwidth').val()) - 8);
    $("#program").css("width", $("#jwidth").val());
    //console.log($("#program div").css("left"));
    $("#program div").each(function () {
      var reg = new RegExp("px", "g");
      if (parseInt($("#jwidth").val()) < parseInt($(this).css("width"))) {
        $("#program").css("width", $(this).css("width"));
        $('#jwidth').val($(this).css("width").replace(reg, ""));
      }
    });

    setTimeout(function (i) {
      $("#program div").each(function (i) {
        var reg = new RegExp("px", "g");
        // console.log($("#program").css("margin-left"));
        //	$(this).css("left",'');
        // $(this).find("#leftdw").val($(this).css("left").replace(reg, ""));
        // i=i+1;

        // $(".col-md-9").find(".form-inline").find("#left").val(0);

      }), 100
    });



  });
  $('.spinner .btn:first-of-type').eq(7).on('click', function () {
    // return;
    $('#jhigh').val(parseInt($('#jhigh').val()) + 1);
    // if($("#jhigh").val()>190){
    // $("#jhigh").val(190);
    // $("#program").css("height",190);
    //return;
    //}else{
    $("#program").css("height", $("#jhigh").val());
    //$("#program").find("div").css("top","0px");

    //}

  });
  $('.spinner .btn:last-of-type').eq(7).on('click', function () {
    //return;
    var value = parseInt($('#jhigh').val()) - 1;

    if (value < 0) {

      return;
    }


    $('#jhigh').val(parseInt($('#jhigh').val()) - 1);
    //   $('#jhigh').val(parseInt($('#jhigh').val())-1);  
    //   if($("#jhigh").val()>190){
    // $("#jhigh").val(190);
    //$("#program").css("height",190);
    // return;
    //}else{
    $("#program").css("height", $("#jhigh").val());
    //$("#program").find("div").css("top","0px");
    //}
  });
  //节目信息 宽 高
  $("#jwidth").blur(function () {
    //alert($('#program').position().left);
    //$('#jwidth').bind('input propertychange', function() {
    //var widthzt=true;
    $("#program").css("width", $("#jwidth").val());
    //console.log($("#program div").css("left"));
    $("#program .transparent_class").each(function () {
      var reg = new RegExp("px", "g");
      if (parseInt($("#jwidth").val()) < parseInt($(this).css("width"))) {
        $("#program").css("width", $(this).css("width"));
        $('#jwidth').val($(this).css("width").replace(reg, ""));
      }
    });

    setTimeout(function (i) {
      $("#program div").each(function (i) {
        var reg = new RegExp("px", "g");
        // console.log($("#program").css("margin-left"));
        //	$(this).css("left",'');
        // $(this).find("#leftdw").val($(this).position().left+"px".replace(reg, ""));
        // i=i+1;

        //$(".col-md-9").find(".form-inline").find("#left").val(0);

      }), 100
    });
  });
  $("#jhigh").blur(function () {
    //$('#jhigh').bind('input propertychange', function() {
    //if($("#jhigh").val()>190){
    // $("#jhigh").val(190);
    // $("#program").css("height",190);
    // return;
    //}else{
    $("#program").css("height", $("#jhigh").val());

    //$("#program div").css("height",$("#jhigh").val());
    //}
  });
  //添加分区
  var guid = "";
  //selectid=guid;
  $("#materialinfo li a").click(function () {


    //return;
    // alert($(this).html())
    if ($(this).text() == " 动画") {
      var gifsize = $("img[src='static/img/sp.png']").length - 1;
      if (gifsize > 0) {
        swal("提示", " 节目只支持1个动画分区显示", "info");
        return false;
      }
    }
    //alert();
    if ($(".transparent_class").length == 3) {

      swal("提示", "节目分区最多可以添加3个", "info");
      return false;
    }

    guid = uuid();
    selectid = guid;
    //console.log(guid);
    //console.log(selectid);
    $("#material li").removeAttr("style");
    $("#material").append("<li id=" + guid + "  style=background-color:#eee;><a ><img src=" + $(this).find("img").attr("src") + " class='img-rounded' style='width: 25px;'>" + $(this).text() + "<img src='static/img/del.png' style='width:26px;float:right;' onclick=del(this) class='img-rounded'></a></li>");
    //alert($(".form-inline").eq(1).html());
    //<form class="form-inline" role="form" 
    //添加分区信息
    //alert($(this).text());
    $("#fqfrom").hide();
    $(".col-md-9").find(".scheduler-border").hide();
    //$(".col-md-9").find(".form-inline").hide();
    //$("#splitscreen").css("height",$("#jhigh").val()+"px");
    //console.log($(this).text());



    if ($(this).text() == " 文本") {
      //return;
      //$(".col-md-9").append("<form class='form-inline' id=from_"+guid+" role='form'>"+$(".form-inline").eq(1).html()+"</from>");

      //分区文本所有内容
      var html = $(".col-md-9").find(".form-inline").eq(0).html().replace("container", "container" + guid);

      $(".col-md-9").append("<fieldset  class=scheduler-border style='border:none;border-top: 1px solid rgb(66, 139, 202);'><legend class='scheduler-border' style='margin-bottom: 0px'>分区信息</legend><form class='form-inline' id=from_" + guid + " role='form'>" + html + "</from></fieldset>");

      $("#from_" + selectid).find("#fosizeval").hide();
      //#fontcolordiv,
      $("#from_" + selectid).find("#fontsizediv").hide();

      
      if (sessionStorage.getItem("type") == "0" || sessionStorage.getItem("type") == "1") {
        $("#texttype option[value='1']").remove()

       
        //#fontcolordiv,
        $("#fontsizediv,#fosizeval").show();

      }
      var _uat = navigator.userAgent;
      if (_uat.indexOf("Firefox") > 0) {
        $("#texttype option[value='1']").remove()
        //#fontcolordiv,
        $("#container" + selectid).hide();
        $("#fontsizediv,#fosizeval").show();

      }

      $("#from_" + guid).find("#backcolor").parent().removeClass("col-sm-3");
      $("#from_" + guid).find("#backcolor").parent().addClass("col-sm-4");

      $("#from_" + guid).find("#type").val(0);

      



      if (sessionStorage.getItem("type") == "0" || sessionStorage.getItem("type") == "1") {
        $("#texttype option[value='1']").remove()

        $("#container" + selectid).hide();
        //#fontcolordiv,
        $("#fontsizediv,#fosizeval").show();


        $("#from_" + guid).find("#typefaceval").attr("disabled", true);
      }

      var _uat = navigator.userAgent;
      if (_uat.indexOf("Firefox") > 0) {
        $("#texttype option[value='1']").remove()

        $("#container" + guid).hide();
        //#fontcolordiv,
        $("#fontsizediv,#fosizeval").show();

      }
      $("#from_" + guid).find("#backcolor").parent().removeClass("col-sm-3");
      $("#from_" + guid).find("#backcolor").parent().addClass("col-sm-4");

      $("#from_" + guid).find("#type").val(0);

      $("#from_" + guid).find("#texttype").change(function () {


        $("#program_" + selectid).html("");

          //自己写的word字体，没用组件
          $("#from_" + selectid).find("#text_pic_form").hide();

          //电脑字体（QQ），隐藏
        if ($(this).val() == "1" || $(this).val() == "2") {

     
          //#fontcolordiv,
          $("#fontcolordiv,#fontsizediv,#fosizeval").hide();
          $("#program_" + selectid).css("line-height", "");
          $("#from_" + selectid).find("#fosizeval").val("");


          $("#from_" + selectid).find("#Dazzle").parent().hide();
          $("#from_" + selectid).find("#typefaceval").parent().hide();

          $("#from_" + selectid).find("#randomFontColor").parent().hide();
          $("#from_" + selectid).find("#randomFontColor").val(0);
          $("#from_" + selectid).find("#typefaceval").val("");
          $("#from_" + selectid).find("#alignment").val("0");
          $("#from_" + selectid).find("#alignment").parent().hide();
          $("#from_" + selectid).find("#Dazzle").html("<option value='0'>无效果</option>");
          $("#from_" + selectid).find(".text-align button").show();
          $("#from_" + selectid).find("#text_pic_form").show();
          init();//电脑字体
          Canvasfont();
        } else {
     

       
          $("#fontcolordiv,#fontsizediv,#fosizeval").show();
          $("#program_" + selectid).css("line-height", "1");
          // $("#from_" + selectid).find("#fontcolor").val("red");
          //$("#from_" + selectid).find("#fontsizeadd").val("1");
          $("#from_" + selectid).find("#typefaceval").val("");

          $("#from_" + selectid).find("#Dazzle").parent().show();
          //$("#from_" + selectid).find("#typefaceval").parent().show();
          // $("#from_" + selectid).find("#randomFontColor").parent().show();
          $("#from_" + selectid).find("#typefaceval").trigger('change');
          $("#from_" + selectid).find("#text_pic_form").hide();

        }
        new ZResize({
          stage: "#program", //舞台 
          item: '#program_' + selectid, //可缩放的类名 
        });
      });

      //默认选择文本
      $("#from_" + selectid).find("#texttype").val("0");
      $("#container" + selectid).hide();

      $("#fontcolordiv,#fontsizediv,#fosizeval").show();
      $("#program_" + selectid).css("line-height", "1");


      //  $("#from_" + selectid).find("#fontcolor").val("red");
      //  $("#from_" + selectid).find("#fontsizeadd").val("1");
    }
    if ($(this).text() == " 图片") {

      //$(".col-md-9").append("<form class='form-inline' id=from_"+guid+" role='form'>"+$(".form-inline").eq(1).html()+"</from>");


      $(".col-md-9").append("<fieldset  class=scheduler-border style='border:none;border-top: 1px solid rgb(66, 139, 202);'><legend class='scheduler-border' style='margin-bottom: 0px'>分区信息</legend><form class='form-inline' id=from_" + guid + " role='form'>" + $(".col-md-9").find(".form-inline").eq(0).html() + "</from></fieldset>");



      $("#from_" + guid).find("#backcolor").parent().removeClass("col-sm-4");
      $("#from_" + guid).find("#backcolor").parent().addClass("col-sm-3");
      $("#from_" + guid).find("#texttype").parent().hide();

      //alert($("#backcolor").parent());
      //alert(123);
      $("#from_" + guid).find("#randomFontColor").parent().hide();
      $("#from_" + guid + "").find("#fontcolor").parent().remove();
      $("#from_" + guid + "").find("#fontsizeadd").parent().remove();
      $("#from_" + guid + "").find("#fosizeval").parent().remove();
      //fontcolor    

      $("#from_" + guid + "").find("#Dazzle").parent().remove();
      $("#from_" + guid + "").find("#typefaceval").parent().remove();


      $("#from_" + guid + "").find("#imgadd").show();

      $("#from_" + guid + "").css("height", 230); $("#from_" + guid).find("#type").val(1);

      //图片排列
      var jj = -1; var ii = -1;
      $(".col-md-9").find(".item").each(function (i) {
        if ($(this).parent().parent().parent().parent().index() > 1) {

          if ($(this).parent().parent().attr("id").toString() == "imgadd") {

            if ($(this).parent().parent().css('display') != "none") {
              ii++;
              $(this).find("#hfile1").val(ii);

            }
          }
        }
      });
      overlap();
    }

    if ($(this).text() == " 动画") {



      $(".col-md-9").append("<fieldset  class=scheduler-border style='border:none;border-top: 1px solid rgb(66, 139, 202);'><legend class='scheduler-border' style='margin-bottom: 0px'>分区信息</legend><form class='form-inline' id=from_" + guid + " role='form'>" + $(".col-md-9").find(".form-inline").eq(0).html() + "</from></fieldset>");

      $("#from_" + guid).find("#type").val(2);
      //alert(123);
      $("#from_" + guid).find("#texttype").parent().hide();
      $("#from_" + guid).find("#randomFontColor").parent().hide();
      $("#from_" + guid + "").find("#fontcolor").parent().remove();
      $("#from_" + guid + "").find("#fontsizeadd").parent().remove();
      $("#from_" + guid + "").find("#fosizeval").parent().remove();
      //fontcolor    
      $("#from_" + guid).find("#backcolor").parent().removeClass("col-sm-4");
      $("#from_" + guid).find("#backcolor").parent().addClass("col-sm-3");
      $("#from_" + guid + "").find("#imgaddgif").show();
      $("#from_" + guid + "").find("#Dazzle").parent().remove();
      $("#from_" + guid + "").find("#typefaceval").parent().remove();
      $("#from_" + guid + "").css("height", 230);
      $("#from_" + guid + "").find("#inspeed").val(0);
      $("#from_" + guid).find("#eninText").html("gif速度&ensp;&emsp;&thinsp;&zwnj;&ensp; &emsp; &thinsp; &zwnj;&zwj;&zwnj;");
      $("#from_" + guid).find(".spinner:eq(5)").parent().hide();
      $("#from_" + guid).find("#intype").parent().hide();
      //图片排列
      var jj = -1; var ii = -1;
      $(".col-md-9").find(".item").each(function (i) {
        if ($(this).parent().parent().parent().parent().index() > 1) {
          if ($(this).parent().parent().attr("id").toString() == "imgaddgif") {
            if ($(this).parent().parent().css('display') != "none") {
              ii++;
              $(this).find("#hfile2").val(ii);

            }
          }
        }
      }); overlap();
    }
    $("#from_" + guid).find("#type").attr("disabled", "disabled");

    $(".panel-heading").click(function () {
      $(".col-md-9").find(".scheduler-border").hide();
      $("#fqfrom").show(); $("#fqfrom").find('.scheduler-border').show();
    });

    $("#material li").eq($("#program").find(".transparent_class").length).click(function () {
      var indx = $(this).index();
      $("#material li").removeAttr("style");
      $(this).css("background-color", "#eee");
      //$("#fqfrom").hide();
      $(".col-md-9").find(".scheduler-border").hide();
      //$(".col-md-9").find(".form-inline").hide();
      //alert($("#from_"+selectid).parent().html());
      //alert($(this).attr("id"));
      var valid = $(this).attr("id");
      selectid = valid;


      $("#from_" + selectid).parent().show();
      $("#from_" + selectid).parent().find('.scheduler-border').show();

      $("#program_" + selectid).css("z-index", $("#program").find("div").length);


      //重新排列分区
      //$("#material li")

      // $("#material li").each(function (i) {
      //   var ifi = i + 1;
      //   if (ifi != indx) {
      //     $("#program_" + $(this).attr("id")).css("z-index", i);
      //   } else {

      //     $("#program_" + $(this).attr("id")).css("z-index", $("#material li").length + 1);
      //   }

      // });

      //if($("#from_"+selectid).find("#texttype").val()=="1"){
      //$("#from_"+selectid).find("#fontsizediv").hide();
      //$("#from_"+selectid).find("#fontcolordiv").hide();
      //$("#from_"+selectid).find("#fosizeval").hide();
      //}else{

      // $("#from_"+selectid).find("#fosizeval").show();
      //}
      if ($("#from_" + selectid).find("#texttype").val() == "1" || $(this).val() == "2") {
        //  if($(this).val()=="1"){
       
        //#fontcolordiv,
        $("#fontsizediv,#fosizeval").hide();
        // $("#program_"+selectid).css("line-height","");

      } else {



        $("#container" + selectid).hide();
        //#fontcolordiv,
        $("#fontsizediv,#fosizeval").show();
        $("#program_" + selectid).css("line-height", "1");
        //  $("#from_" + selectid).find("#fontcolor").val("red");
        //  $("#from_" + selectid).find("#fontsizeadd").val("1");
      }




    });
    if (widthlocal == 0) {
      //预览
      var fqvalue = "<div id=program_" + guid + " class='transparent_class' style='top:0px;position: absolute;z-index:" + $("#program").find(".transparent_class").length + ";border:2px dashed #FFFFFF; width:" + $("#jwidth").val() + "px;height:" + $("#jhigh").val() + "px; background-color:#000000;'> <input type='hidden' id='leftdw'/></div>";
      //var fqvalue="<div id=program_"+ guid+" class='transparent_class' style='top:0px;position: absolute;z-index:"+$("#program").find("div").length+";border:2px dashed #FFFFFF; width:"+$("#jwidth").val()+"px;height:"+$("#jhigh").val()+"px; background-color: #413d3d;'> <input type='hidden' id='leftdw'/></div>";

    } else {
      //alert(widthlocal);
      var fqvalue = "<div id=program_" + guid + " class='transparent_class' style='top:0px;position: absolute;z-index:" + $("#program").find(".transparent_class").length + ";border:2px dashed #FFFFFF; width:" + widthlocal + "px;height:" + heightlocal + "px; background-color: #000000;'> <input type='hidden' id='leftdw'/></div>";
    }
    $("#program").append(fqvalue);

    new ZResize({
      stage: "#program", //舞台 
      item: '#program_' + guid, //可缩放的类名 
    });

    $('#from_' + selectid).find("#width").val($("#jwidth").val());
    $('#from_' + selectid).find("#high").val($("#jhigh").val());
    // ("#jwidth").val()
    // $('#program_' + selectid).css("background-color", $('#from_' + selectid).find("#backcolor").val());

    //alert($('#program_'+selectid).position().left);

    var leftwz = $('#program_' + selectid).position().left + "px";


    var reg = new RegExp("px", "g");
    leftwz = leftwz.replace(reg, "");

    $('#program_' + selectid).find("#leftdw").val(leftwz);

    //$( "#draggable3" ).draggable({  });
    //var  counts = [ 0, 0, 0 ];
    //$('#program_'+selectid).draggable123456({
    // containment: "#program", scroll: false,
    //  start: function() {
    //  var  valid=$(this).attr("id");
    //  valid=valid.split('_');
    //  alert(valid[1]);
    //console.log();
    // selectid=valid[1];
    //	counts[ 0 ]++;
    //	console.log($(this).attr("id"));
    // updateCounterStatus( $start_counter, counts[ 0 ] );
    // },
    //drag: function() {
    //counts[ 1 ]++;
    //console.log($('#program_'+selectid).css("left"));
    //  },
    // stop: function() {
    //  return;
    //counts[ 2 ]++;
    //var left=$('#program_'+selectid).css("left");

    //var top=$('#program_'+selectid).css("top");

    // var reg = new RegExp("px","g");
    //left = left.replace(reg, "");

    //alert($('#program_'+selectid).find("#leftdw").val());
    //alert($('#program_'+selectid).find("#leftdw").val());

    //left=parseInt(left)-parseInt($('#program_'+selectid).find("#leftdw").val());


    //left=parseInt(left)-parseInt(leftwz);
    //$('#from_'+selectid).find("#left").val(left);
    //top = top.replace(reg, "");

    //$('#from_'+selectid).find("#top").val(parseInt(top));
    //} 
    //});
    //节目信息分区 宽 高

    $('#from_' + selectid).find("#inspeed").blur(function () {
      if ($(this).val() == "") {

        $(this).val(1);
      }
      //验证可以为负数、0、正数
      var regu = /^-?[1-9]+[0-9]*$|^0$/;
      if (!regu.test($(this).val())) {
        var speedlabel = $(this).parent().prev().text().toString();
        speedlabel = speedlabel.substring(0, 3);

        if (speedlabel.trim() == "gif") {
          swal("OMA", "gif速度的格式不正确，请正确书写！", "error");
          $(this).val(0);
          return false;
        }
      }
    });
    $('#from_' + selectid).find("#width").blur(function () {
      if ($(this).val() == "") {
        $(this).val(0);
        $("#program_" + selectid).width(0);
      }

    });

    $('#from_' + selectid).find("#high").blur(function () {
      if ($(this).val() == "") {
        $(this).val(0);
        $("#program_" + selectid).height(0);
      }

    });

    $('#from_' + selectid).find("#staytime").blur(function () {
      if ($(this).val() == "") {
        $(this).val(1);
      }

    });
    $('#from_' + selectid).find("#width").bind('input propertychange', function () {

      if ($(this).val() == "") {

        $(this).val(0);
      }
      var val = $(this).val().substr(0, 1);
      if (val == "0") {
        $(this).val(0);
      }
      var zoomsum = parseInt($("#zoomsum").text());
      console.log("zoomsum")
      if (parseInt($('#from_' + selectid).find("#width").val()) > parseInt($("#jwidth").val())) {

        $('#from_' + selectid).find("#left").val(0);
        $("#program_" + selectid).css("width", $("#jwidth").val());
        $('#from_' + selectid).find("#width").val($("#jwidth").val());

        if (zoomsum > 0) {
          zoomsum = zoomsum * 2;
          var w = parseInt($('#from_' + selectid).find("#width").val()) * parseInt(zoomsum);
          $("#program_" + selectid).css("width", w);
        }
        // $('#program_'+selectid).css("left",leftwz+"px");
        $('#program_' + selectid).css("left", $('#program_' + selectid).find("#leftdw").val() + "px");
        //画布
        textcanvas(selectid);
        onblurdiv();
        return;
      } else {
        var w = parseInt($('#from_' + selectid).find("#width").val());
        if (zoomsum > 0) {
          zoomsum = zoomsum * 2;
          w = parseInt($('#from_' + selectid).find("#width").val()) * parseInt(zoomsum);
        }

        $("#program_" + selectid).css("width", w);



        if (parseInt($('#from_' + selectid).find("#width").val()) == parseInt($("#jwidth").val())) {


          //console.log(leftwz);

          $('#from_' + selectid).find("#left").val(0);


          // console.log($("#program").css("left"));

          //$('#program_'+selectid).css("left",leftwz+"px");
          $('#program_' + selectid).css("left", $('#program_' + selectid).find("#leftdw").val() + "px");




          // return;
        }

        console.log("宽：" + $('#from_' + selectid).find("#width").val());
        var left = parseInt($('#from_' + selectid).find("#left").val()) + parseInt($('#from_' + selectid).find("#width").val());
        if (left > $("#jwidth").val()) {
          //left=parent(left)-parseInt($("#jwidth").val());
          var reg = new RegExp("px", "g");

          //console.log(left);

          //left=parseInt($('#program_'+selectid).css("left").replace(reg, ""))-parseInt(left);


          left = parseInt($('#program_' + selectid).css("left").replace(reg, "")) - parseInt($('#from_' + selectid).find("#left").val());


          //console.log(left);
          $('#from_' + selectid).find("#left").val(0);
          $("#program_" + selectid).css("left", left + "px");

          //$('#from_'+selectid).find("#width").val( $("#jwidth").val());


          //$('#from_'+selectid).find("#width").val(parseInt($("#jwidth").val())-parseInt($('#from_'+selectid).find("#left").val()));
          //$("#program_"+selectid).css("width",parseInt($("#jwidth").val());
          //console.log(left);
        }
      }
      //画布
      textcanvas(selectid);
      //if(){
      // }
      onblurdiv();

    });

    $('#from_' + selectid).find("#high").bind('input propertychange', function () {

      if ($(this).val() == "") {

        $(this).val(0);
      }
      var val = $(this).val().substr(0, 1);
      if (val == "0") {
        $(this).val(0);
      }
      var zoomsum = parseInt($("#zoomsum").text());
      //输入的高度要是大于总高，就退回原来总长
      if (parseInt($('#from_' + selectid).find("#high").val()) > parseInt($("#jhigh").val())) {
        $("#program_" + selectid).css("height", $("#jhigh").val() + "px");
        $('#from_' + selectid).find("#high").val($("#jhigh").val());
        //if($("#program_"+selectid).find("img").val()==""){
        //$("#program_"+selectid).find("img").css("height",$("#jhigh").val()+"px");
        //$("#program_"+selectid).find("img").css("height",parseInt($("#jhigh").val())-4+"px");
        // console.log("ok");
        //$('#from_'+selectid).find("#top").val(0);
        //}

        if (zoomsum > 0) {
          zoomsum = zoomsum * 2;
          var h = parseInt($('#from_' + selectid).find("#high").val()) * parseInt(zoomsum);
          $("#program_" + selectid).css("height", h + "px");
        }

        $('#from_' + selectid).find("#top").val(0);
        $('#program_' + selectid).css("top", 0 + "px");
        //画布
        textcanvas(selectid);
        onblurdiv();
        return;
      }
      var h = parseInt($('#from_' + selectid).find("#high").val());
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        h = parseInt($('#from_' + selectid).find("#high").val()) * parseInt(zoomsum);
      }
      $("#program_" + selectid).css("height", h);

      //if($("#program_"+selectid).find("img").val()==""){

      //$("#program_"+selectid).find("img").css("height",parseInt($('#from_'+selectid).find("#high").val())-4);

      //}
      var top = parseInt($('#from_' + selectid).find("#top").val()) + parseInt($('#from_' + selectid).find("#high").val());

      //console.log(top);
      console.log("高：" + $('#from_' + selectid).find("#high").val());

      if (top > $("#jhigh").val()) {
        var reg = new RegExp("px", "g");
        top = parseInt($('#program_' + selectid).css("top").replace(reg, "")) - parseInt($('#from_' + selectid).find("#top").val())
        $("#program_" + selectid).css("top", top + "px");
        $('#from_' + selectid).find("#top").val(0);

      }

      if (parseInt($('#from_' + selectid).find("#high").val()) == parseInt($("#jhigh").val())) {


        //console.log(leftwz);

        $('#from_' + selectid).find("#top").val(0);


        // console.log($("#program").css("left"));

        $('#program_' + selectid).css("top", 0 + "px");



        // return;
      }
      //画布
      textcanvas(selectid);
      onblurdiv();
    });
    //节目信息分区 x y
    $('#from_' + selectid).find("#left").bind('input propertychange', function () {
      if ($(this).val() == "") {

        $(this).val(0);

      }
      if ($(this).val() < 0) {
        return;
      }
      var zoomsum = parseInt($("#zoomsum").text());
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        var h = parseInt($(this).val()) * zoomsum;
        $("#program_" + selectid).css("left", h + "px");
      }
      if (zoomsum == 0) {
        $("#program_" + selectid).css("left", $(this).val() + "px");
      }

      Zonexy($("#program_" + selectid));

      var val = $(this).val().substr(0, 1);

      if (val == "0") {
        console.log("等于0")
        $(this).val(0);
      }
      //画布
      textcanvas(selectid);
      return;

      var left = parseInt($("#jwidth").val()) - parseInt($('#from_' + selectid).find("#width").val());

      //var lefttow=parseInt(leftwz)+parseInt($('#from_'+selectid).find("#left").val());
      var lefttow = parseInt($('#program_' + selectid).find("#leftdw").val()) + parseInt($('#from_' + selectid).find("#left").val());


      if ($('#from_' + selectid).find("#left").val() > left) {

        $('#from_' + selectid).find("#left").val(left)
        // left=parseInt(leftwz)+parseInt(left);
        left = parseInt($('#program_' + selectid).find("#leftdw").val()) + parseInt(left);

        $("#program_" + selectid).css("left", left + "px");
        // $("#program_"+selectid).css("margin-left",left+"px");

        return;
      }

      $("#program_" + selectid).css("left", lefttow + "px");
      // $("#program_"+selectid).css("margin-left",$('#from_'+selectid).find("#left").val()+"px");
    });
    $('#from_' + selectid).find("#top").bind('input propertychange', function () {
      if ($(this).val() == "") {

        $(this).val(0);
      }
      var zoomsum = parseInt($("#zoomsum").text());
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        var h = parseInt($(this).val()) * zoomsum;
        $("#program_" + selectid).css("top", h + "px");
      }
      if (zoomsum == 0) {


        $("#program_" + selectid).css("top", $(this).val() + "px");
      }
      Zonexy($("#program_" + selectid));
      var val = $(this).val().substr(0, 1);

      if (val == "0") {

        $(this).val(0);
      }
      //画布
      textcanvas(selectid);
      return;

      // $("#program_"+selectid).css("margin-top",$('#from_'+selectid).find("#top").val()+"px");

    });

    //字体输入
    $('#from_' + selectid).find("textarea").bind('input propertychange', function () {


      //预览，生成的
      $("#program_" + selectid).html("<input type='hidden' id='imgDataURL'><input type='hidden' id='leftdw' value=" + $("#program_" + selectid).find("#leftdw").val() + ">");
      $("#program_" + selectid).css("line-height", 1);

      //textarea颜色不明显的不变色
      if ($('#from_' + selectid).find("#fontcolor").val() == "white" || $('#from_' + selectid).find("#fontcolor").val() == "yellow") {
        console.log("互")
        $('#from_' + selectid).find("textarea").css("color", "black");
      } else {
        $('#from_' + selectid).find("textarea").css("color", $('#from_' + selectid).find("#fontcolor").val());
      }

      // $("#program_" + selectid).css("line-height", 1);

      //$("#program_" + selectid).find("div").css("display","").css("align-items","");
      //var  alignment=$("#from_"+selectid).find("#alignment").val()=="0"?"left":
      //$("#from_"+selectid).find("#alignment").val()=="1"?"right":"center";
      //$("#program_" + selectid).find("div").css("text-align",alignment);

      //var  alignment=$("#from_"+selectid).find("#alignment").val()=="2"
      if ($("#from_" + selectid).find("#alignment").val() == "0") {

        $("#program_" + selectid).css("display", "");
        $("#program_" + selectid).css("align-items", "");
      }
      if ($("#from_" + selectid).find("#alignment").val() == "2") {
        $("#program_" + selectid).css("display", "grid");
        $("#program_" + selectid).css("align-items", "flex-end");
      }
      if ($("#from_" + selectid).find("#alignment").val() == "1") {

        $("#program_" + selectid).css("display", "grid");
        $("#program_" + selectid).css("align-items", "center");

      }
      //imgDataURL
      var reg = new RegExp("px", "g");
      var size = $('#from_' + selectid).find("#fontsizeadd").find("option:selected").text().replace(reg, "");

      size = size.split("*")[0];
      $("#program_" + selectid).css("font-size", size + "px");


      if (zoomsum > 0) {
        var zoomsumval = zoomsum * 2;
        zoomsumval = size * zoomsumval;
        $("#program_" + selectid).css("font-size", zoomsumval + "px");
      }
      //size=size*2;

      //var sizepx=$("#program_"+selectid).css("height").replace(reg, "");
      //if(sizepx<size)
      // $("#program_"+selectid).css("height",size+"px");

      new ZResize({
        stage: "#program", //舞台 
        item: '#program_' + selectid, //可缩放的类名 
      });
      //画布
      textcanvas(selectid);
    });



    //炫彩效果
    $('#from_' + selectid).find("#Dazzle").click(function () {
      //  $('#myModalxc').modal();
      // alert(123);
      $("#selectxc").click();
      //  $('#myModalmb').modal('show');
    });
    //字体
    $('#from_' + selectid).find("#typefaceval").change(function () {
      //  $('#myModalxc').modal();

      $("#program_" + selectid).find("div").css("font-family", $(this).val());
      $("#fosizeval").css("font-family", $(this).val());
      if ($(this).val() == "") {
        $("#program_" + selectid).css("display", "");
        $("#program_" + selectid).css("align-items", "");
        $("#from_" + selectid).find("#alignment").parent().hide();
        //  $("#from_"+selectid).find("#typefaceval").parent().css("margin-left","")

        $("#from_" + selectid).find("#randomFontColor").val("0");
        $("#from_" + selectid).find("#Dazzle,#randomFontColor").parent().hide();


      } else {
        //  $("#from_" + selectid).find("#alignment").parent().show();
        // $("#from_"+selectid).find("#Dazzle").parent().css("margin-left","-24.8%");
        $("#from_" + selectid).find("#Dazzle").parent().show();
        // $("#from_" + selectid).find("#Dazzle,#randomFontColor").parent().show();
        //  $("#from_"+selectid).find("#typefaceval").parent().css("margin-left","-50%")

      }
      // if($(this).val()!=""){
      //   $('#from_' + selectid).find("#randomFontColor").val("0");
      // }
      //  $("#selectxc").click();
      //  $('#myModalmb').modal('show');
    });
    //对齐方式
    $('#from_' + selectid).find("#alignment").click(function () {

      if ($("#from_" + selectid).find("#alignment").val() == "0") {

        $("#program_" + selectid).css("display", "");
        $("#program_" + selectid).css("align-items", "");
      }
      if ($("#from_" + selectid).find("#alignment").val() == "2") {
        $("#program_" + selectid).css("display", "grid");
        $("#program_" + selectid).css("align-items", "flex-end");
      }
      if ($("#from_" + selectid).find("#alignment").val() == "1") {

        $("#program_" + selectid).css("display", "grid");
        $("#program_" + selectid).css("align-items", "center");

      }

    });
    //字体特效
    $('#from_' + selectid).find("#randomFontColor").change(function () {

      if ($(this).val() != "0") {
        $('#from_' + selectid).find("#typefaceval").val("SimSun");
        $('#from_' + selectid).find("#Dazzle").parent().hide();
        $('#from_' + selectid).find("#alignment").parent().show();
        $('#from_' + selectid).find("#randomFontColor").parent().css("margin-left", "-24.8%");

      } else {
        $('#from_' + selectid).find("#typefaceval").val("");
        $('#from_' + selectid).find("#Dazzle").parent().show();
        $('#from_' + selectid).find("#alignment").parent().hide();
        $('#from_' + selectid).find("#Dazzle").parent().css("margin-left", "");
        $('#from_' + selectid).find("#randomFontColor").parent().css("margin-left", "");
      }

    });
    //字体大小
    $('#from_' + selectid).find("#fontsizeadd").change(function () {
      var reg = new RegExp("px", "g");
      var size = $(this).find("option:selected").text().replace(reg, "").split("*")[0];
      //$("#program_"+selectid).css("font-size",size[1]+"px");
      $("#program_" + selectid).css("font-size", size + "px");
      if (zoomsum > 0) {
        var zoomsumval = zoomsum * 2;
        zoomsumval = size * zoomsumval;
        $("#program_" + selectid).css("font-size", zoomsumval + "px");
      }
      //画布
      textcanvas(selectid);
    });
    //字体颜色
    $('#from_' + selectid).find("#fontcolor").change(function () {
      //   $("#program_" + selectid).css("color", $(this).val());

      if ($(this).val() == "white" || $(this).val() == "yellow") {
        $('#from_' + selectid).find("textarea").css("color", "black");
      } else {
        $('#from_' + selectid).find("textarea").css("color", $(this).val());
      }
      //画布
      textcanvas(selectid);
      // $(this).css("background-color","#FFFFCC");
    });


    //背景颜色
    $('#from_' + selectid).find("#backcolor").change(function () {
      //	$("#program_"+selectid).css("background-color",$(this).val());
    });

    //向左移
    $('#from_' + selectid).find('.spinner .btn:first-of-type').eq(0).on('click', function () {
      $('#from_' + selectid).find("#left").val(parseInt($("#program_" + selectid).css("left")) + 8);
      $("#program_" + selectid).css("left", $('#from_' + selectid).find("#left").val() + "px");
      var zoomsum = parseInt($("#zoomsum").text());
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        var left = parseInt($("#program_" + selectid).css("left")) / zoomsum;
        if (left > 4) {
          $('#from_' + selectid).find("#left").val(parseInt(left));
        }
      }
      Zonexy($("#program_" + selectid));
      //画布
      textcanvas(selectid);
      return;
    });
    $('#from_' + selectid).find('.spinner .btn:last-of-type').eq(0).on('click', function () {
      // $('.spinner input').val(parseInt($('.spinner input').val()) - 8);  
      var value = parseInt($('#from_' + selectid).find("#left").val()) - 8;
      if (value < 0) {
        $('#from_' + selectid).find("#left").val(parseInt(0)); $("#program_" + selectid).css("left", 0);
        return;
      }
      $('#from_' + selectid).find("#left").val(parseInt($("#program_" + selectid).css("left")) - 8);
      $("#program_" + selectid).css("left", $('#from_' + selectid).find("#left").val() + "px");
      var zoomsum = parseInt($("#zoomsum").text());
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        var left = parseInt($("#program_" + selectid).css("left")) / zoomsum;
        $('#from_' + selectid).find("#left").val(parseInt(left));
      }
      //画布
      textcanvas(selectid);
      return;
    });

    //向上移
    $('#from_' + selectid).find('.spinner .btn:last-of-type').eq(1).on('click', function () {
      // $('.spinner input').val(parseInt($('.spinner input').val()) - 8);  
      var value = parseInt($('#from_' + selectid).find("#top").val()) - 8;
      if (value < 0) {
        $('#from_' + selectid).find("#top").val(parseInt(0)); $("#program_" + selectid).css("top", 0);

        return;
      }
      $('#from_' + selectid).find("#top").val(parseInt($("#program_" + selectid).css("top")) - 8);
      $("#program_" + selectid).css("top", $('#from_' + selectid).find("#top").val() + "px");
      var zoomsum = parseInt($("#zoomsum").text());
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        var top = parseInt($("#program_" + selectid).css("top")) / zoomsum;
        $('#from_' + selectid).find("#top").val(parseInt(top));
      }

      return;
    });

    $('#from_' + selectid).find('.spinner .btn:first-of-type').eq(1).on('click', function () {
      //$('#from_'+selectid).find("#top").val(parseInt($('#from_'+selectid).find("#top").val()) +8);
      //$("#program_"+selectid).css("top",$('#from_'+selectid).find("#top").val()+"px");	

      $('#from_' + selectid).find("#top").val(parseInt($("#program_" + selectid).css("top")) + 8);
      $("#program_" + selectid).css("top", $('#from_' + selectid).find("#top").val() + "px");
      var zoomsum = parseInt($("#zoomsum").text());
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        var top = parseInt($("#program_" + selectid).css("top")) / zoomsum;
        if (top > 4) {
          $('#from_' + selectid).find("#top").val(parseInt(top));
        }
      }
      Zonexy($("#program_" + selectid));

      return;



    });

    //宽度
    $('#from_' + selectid).find('.spinner .btn:first-of-type').eq(2).on('click', function () {

      var zoomsum = parseInt($("#zoomsum").text());
      if (parseInt($('#from_' + selectid).find("#width").val()) + 8 > parseInt($("#jwidth").val())) {

        if (zoomsum > 0) {
          zoomsum = zoomsum * 2;
          var w = parseInt(parseInt($("#jwidth").val())) * parseInt(zoomsum);
          $('#from_' + selectid).find("#width").val($("#jwidth").val());
          $("#program_" + selectid).css("width", parseInt(w));

        } else {
          $('#from_' + selectid).find("#width").val($("#jwidth").val());
          $("#program_" + selectid).css("width", $("#jwidth").val());
        }

        Zonexy($("#program_" + selectid));
        //画布
        textcanvas(selectid);
        return;


      }

      $('#from_' + selectid).find("#width").val(parseInt($('#from_' + selectid).find("#width").val()) + 8);
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        var w = parseInt($('#from_' + selectid).find("#width").val()) * parseInt(zoomsum);
        $("#program_" + selectid).css("width", w); Zonexy($("#program_" + selectid));
        //画布
        textcanvas(selectid);
        return;
      } else {
        $("#program_" + selectid).css("width", $('#from_' + selectid).find("#width").val());

        if ($("#program_" + selectid).find("img").val() == "") {

          //$("#program_"+selectid).find("img").css("width",parseInt($('#from_'+selectid).find("#width").val())-4);

        }

        if (parseInt($('#from_' + selectid).find("#width").val()) == parseInt($("#jwidth").val())) {


          //console.log(leftwz);

          //$('#from_'+selectid).find("#left").val(0);
          Zonexy($("#program_" + selectid));

          // console.log($("#program").css("left"));

          //$('#program_'+selectid).css("left",leftwz+"px");
          //  $('#program_'+selectid).css("left",$('#program_'+selectid).find("#leftdw").val()+"px");



          // return;
        }


        var left = parseInt($('#from_' + selectid).find("#left").val()) + parseInt($('#from_' + selectid).find("#width").val());
        if (left > $("#jwidth").val()) {
          //left=parent(left)-parseInt($("#jwidth").val());
          var reg = new RegExp("px", "g");

          //console.log(left);

          //left=parseInt($('#program_'+selectid).css("left").replace(reg, ""))-parseInt(left);


          left = parseInt($('#program_' + selectid).css("left").replace(reg, "")) - parseInt($('#from_' + selectid).find("#left").val());

          //$('#from_'+selectid).find("#left").val(0);
          //console.log(left);

          Zonexy($("#program_" + selectid));

        }
      }

      onblurdiv();
      //画布
      textcanvas(selectid);
    });
    $('#from_' + selectid).find('.spinner .btn:last-of-type').eq(2).on('click', function () {
      var value = parseInt($('#from_' + selectid).find("#width").val()) - 8;
      if (value <= 0) {
        return;
      }
      $('#from_' + selectid).find("#width").val(parseInt($('#from_' + selectid).find("#width").val()) - 8);
      //console.log(123);

      //if(parseInt($('#from_'+selectid).find("#width").val())>parseInt($("#jwidth").val())){
      //$('#from_'+selectid).find("#left").val(0);
      var zoomsum = parseInt($("#zoomsum").text());
      $("#program_" + selectid).css("width", $("#jwidth").val());
      if (zoomsum > 0) {

        zoomsum = zoomsum * 2;

        var w = parseInt($('#from_' + selectid).find("#width").val()) * parseInt(zoomsum);


        //console.log(w);
        $("#program_" + selectid).css("width", w);
        //}
        //$('#from_'+selectid).find("#width").val($("#jwidth").val());
        //$('#program_'+selectid).css("left",$('#program_'+selectid).find("#leftdw").val()+"px");
        Zonexy($("#program_" + selectid));


        // return;
        //return;
      } else {
        $("#program_" + selectid).css("width", $('#from_' + selectid).find("#width").val());

      }

      // Zonexy($("#program_"+selectid));
      onblurdiv();
      //画布
      textcanvas(selectid);
    });

    //高度
    $('#from_' + selectid).find('.spinner .btn:first-of-type').eq(3).on('click', function () {
      var zoomsum = parseInt($("#zoomsum").text());
      var jhigh = parseInt($('#from_' + selectid).find("#high").val()) + 8;
      $('#from_' + selectid).find("#high").val();
      if (jhigh > parseInt($("#jhigh").val())) {
        $('#from_' + selectid).find("#high").val($("#jhigh").val());
        jhigh = $("#jhigh").val();
        //$("#program_"+selectid).css("height",$("#jhigh").val());
        //$("#program_"+selectid).css("height",jhigh+"px");
        //$('#from_'+selectid).find("#high").val(jhigh);
        //if($("#program_"+selectid).find("img").val()==""){
        //$("#program_"+selectid).find("img").css("height",jhigh+"px");
      } $('#from_' + selectid).find("#high").val(jhigh);
      //$('#program_'+selectid).css("top",0+"px");
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        var w = parseInt($('#from_' + selectid).find("#high").val()) * parseInt(zoomsum);

        //console.log(w);
        $("#program_" + selectid).css("height", w);
      } else {

        $("#program_" + selectid).css("height", jhigh);
      }
      //}
      //$('#from_'+selectid).find("#width").val($("#jwidth").val());



      Zonexy($("#program_" + selectid));
      //画布
      textcanvas(selectid);

      return;
      //}
      $("#program_" + selectid).css("height", $('#from_' + selectid).find("#high").val());

      if ($("#program_" + selectid).find("img").val() == "") {

        $("#program_" + selectid).find("img").css("height", parseInt($('#from_' + selectid).find("#high").val()) - 4);

      }
      var top = parseInt($('#from_' + selectid).find("#top").val()) + parseInt($('#from_' + selectid).find("#high").val());

      //console.log(top);

      if (top > $("#jhigh").val()) {
        var reg = new RegExp("px", "g");
        top = parseInt($('#program_' + selectid).css("top").replace(reg, "")) - parseInt($('#from_' + selectid).find("#top").val())
        $("#program_" + selectid).css("top", top + "px");
        $('#from_' + selectid).find("#top").val(0);
      }

      if (parseInt($('#from_' + selectid).find("#high").val()) == parseInt($("#jhigh").val())) {


        //console.log(leftwz);

        $('#from_' + selectid).find("#top").val(0);


        // console.log($("#program").css("left"));

        // $('#program_'+selectid).css("top",0+"px");

        Zonexy($("#program_" + selectid));

        // return;
      }

      onblurdiv();

    });
    $('#from_' + selectid).find('.spinner .btn:last-of-type').eq(3).on('click', function () {

      var value = parseInt($('#from_' + selectid).find("#high").val()) - 8;

      if (value <= 0) {

        return;
      }


      $('#from_' + selectid).find("#high").val(parseInt($('#from_' + selectid).find("#high").val()) - 8);

      var jhigh = parseInt($("#jhigh").val());
      // if($('#from_'+selectid).find("#high").val()>jhigh){
      //	$("#program_"+selectid).css("height",jhigh+"px");
      //	$('#from_'+selectid).find("#high").val(jhigh);

      // if($("#program_"+selectid).find("img").val()==""){


      // $("#program_"+selectid).find("img").css("height",jhigh+"px");


      //  }
      //$('#program_'+selectid).css("top",0+"px");

      var zoomsum = parseInt($("#zoomsum").text());
      //alert(zoomsum);
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        var w = parseInt($('#from_' + selectid).find("#high").val()) * parseInt(zoomsum);

        //console.log(w);
        $("#program_" + selectid).css("height", w);
      }

      //return;
      // }

      if (zoomsum == 0) {
        $("#program_" + selectid).css("height", $('#from_' + selectid).find("#high").val());
      }
      //if($("#program_"+selectid).find("img").val()==""){

      // $("#program_"+selectid).find("img").css("height",parseInt($('#from_'+selectid).find("#high").val())-4);

      //  }
      var top = parseInt($('#from_' + selectid).find("#top").val()) + parseInt($('#from_' + selectid).find("#high").val());

      //console.log(top);

      if (top > $("#jhigh").val()) {
        var reg = new RegExp("px", "g");
        top = parseInt($('#program_' + selectid).css("top").replace(reg, "")) - parseInt($('#from_' + selectid).find("#top").val())
        $("#program_" + selectid).css("top", top + "px");
      }

      if (parseInt($('#from_' + selectid).find("#high").val()) == parseInt($("#jhigh").val())) {


        //console.log(leftwz);

        $('#from_' + selectid).find("#top").val(0);


        // console.log($("#program").css("left"));

        $('#program_' + selectid).css("top", 0 + "px");


        // return;
      }
      Zonexy($("#program_" + selectid));
      onblurdiv();

    });

    //进入速度
    $('#from_' + selectid).find('.spinner .btn:first-of-type').eq(4).on('click', function () {
      $('#from_' + selectid).find("#inspeed").val(parseInt($('#from_' + selectid).find("#inspeed").val()) + 1);
    });
    $('#from_' + selectid).find('.spinner .btn:last-of-type').eq(4).on('click', function () {


      var value = parseInt($('#from_' + selectid).find("#inspeed").val()) - 1;
      var speedlabel = $('#from_' + selectid).find("#inspeed").parent().prev().text().toString();
      speedlabel = speedlabel.substring(0, 3);

      if (speedlabel.trim() != "gif") {
        if (value < 0) {

          return;
        }
      }
      $('#from_' + selectid).find("#inspeed").val(parseInt($('#from_' + selectid).find("#inspeed").val()) - 1);

    });

    //停留时间
    $('#from_' + selectid).find('.spinner .btn:first-of-type').eq(5).on('click', function () {
      $('#from_' + selectid).find("#staytime").val(parseInt($('#from_' + selectid).find("#staytime").val()) + 1);
    });
    $('#from_' + selectid).find('.spinner .btn:last-of-type').eq(5).on('click', function () {


      var value = parseInt($('#from_' + selectid).find("#staytime").val()) - 1;

      if (value <= 0) {

        return;
      }

      $('#from_' + selectid).find("#staytime").val(parseInt($('#from_' + selectid).find("#staytime").val()) - 1);

    });

  });


  var zt = true;
  var overlapval = true;
  window.addjm = function () {
    //var  programsum=$("#program .transparent_class").length;
    //for(var i=0;i<zoomsum;i++){
    //  $("#zoom img").eq(0).click();
    //   $("#zoomsum").text("0");
    //}
    overlapval = true;
    var orderid = 1;
    if ($("#typejm").val() == "2") {
      orderid = 0;
    }
    zt = true;
    var datadd = {};
    if ($("#order").val().length == 0) {
      swal("OMG!", "请选择订单！", "error");
      return;
    }
    if ($("#programid").val() != null) {
      if ($("#programid").val().length == 0) {
        swal("OMG!", "请选择节目号", "error");
        return;
      }
    }
    if ($("#festivalname").val().length == 0) {
      swal("OMG!", "请输入节目名称", "error");
      return;
    }
    if ($("#starttime").val().length == 0) {
      swal("OMG!", "请输入播放起始日期 ", "error");
      return;
    }
    if ($("#endtime").val().length == 0) {
      swal("OMG!", "请输入播放结束日期", "error");
      return;
    }


    
    if ($("#timeid").val().length == 0) {
      swal("OMG!", "请输入开始时段 ", "error");
      return;
    }
    if ($("#starthour").val().length == 0) {
      swal("OMG!", "请输入结束时段", "error");
      return;
    }
   

    // if ($("#programPrice").val().length == 0) {
    //   swal("OMG!", "请输入价格", "error");
    //   return;
    // }
    // if ($("#programPrice").val()==0) {
    //  swal("OMG!", "输入的价格必须要大于0", "error");
    //  return;
    // }
    var date3 = new Date($("#starttime").val());
    var startTime = date3.getTime();

    var date4 = new Date($("#endtime").val());
    var endTime = date4.getTime();
    console.log("时间戳：" + startTime + ",结束：" + endTime)
    if (endTime<=startTime) {
      swal("OMG!", "播放结束日期不能小于等于播放开始日期", "error");
      return;
    }

     var date1 = new Date(getNowFormatDate() + " " +$("#timeid").val());
    var startTime1 = date1.getTime();
    var date2 = new Date(getNowFormatDate() + " " +$("#starthour").val());
    var endTime1 = date2.getTime();
  
    if (endTime1 <= startTime1) {
      swal("OMG!", "播放结束时间段不能小于等于播放开始时间段", "error");
      return;
    }


    if ($("#material li").length == 0) {
      swal("OMG!", "请填写分区信息", "error");
      return;
    }
    $("#error").html("");
    if ($("#material li").length > 1) {
      var sum = $(".transparent_class").length - 1;
      $(".transparent_class").each(function (i) {
        var ii = i;
        if ($(".transparent_class").length > 1) {
          $(".transparent_class").each(function (i) {
            if (ii != i) {
              if (overlapdiv($(".transparent_class").eq(ii), $(".transparent_class").eq(i))) {
                overlapval = false;
                return false;
              }
            }
          });
        } else if ($(".transparent_class").length == 1) {

          if (overlapdiv($(".transparent_class").eq(ii), $(".transparent_class").eq(1))) {
            overlapval = false;
            return false;
          }
        }

        if (!overlapval) {
          $("#error").html("分区不能重叠");
          swal("OMG!", "分区不能重叠", "error");
          overlapval = false;
          return false;
        }
      });
    }
    if (!overlapval) {
      return;
    }
    var programid = parseInt($("#programid").val()) - 1;
    if (programtype == "1") {
      programid = 130;
    }
 
    var programtimeinfolist = new Array();
    //1535738400000
    //alert(startDateM);
    //return;


    if ($("#highTime").is(":checked")) {

      //获取周期

      var checked = new Array();

      $(".current li").each(function (j) {
        if ($(this).find("input").is(":checked")) {
          if($(this).find("input").val()!==null&&$(this).find("input").val()!=""){
            checked[j] = parseInt($(this).find("input").val());
            console.log("回家 "+$(this).find("input").val())
        
          }
        }
      });
      datadd["program"] = ({
        "programPrice": $("#programPrice").val(),
        "programtype": programtype,
        "programid": programid,
        "order_id": orderid,
        "companyid": sessionStorage.getItem("coid"),
        "type": $("#typejm").val(),
        // "starttime": $("#starttime").val()+" "+$("#timeid").val()+":00",
        // "endtime": $("#endtime").val()+" "+$("#starthour").val()+":00",
        "starttime": $("#starttime").val()+" "+"00:00:00",
        "endtime": $("#endtime").val()+" "+"23:59:59",
        "playtime": $("#playtime").val(),
        "devicetype": $("#devicetype").val(),
        "festivalname": $("#festivalname").val(),
        "isplayvoice": $("#isplayvoice").val(),
        "playtype": $("#playtype").val(),
        "days": checked
      });

      //获取时段的值
      var stime = ""; var etime = "";
      var sArr = ['']; var eArr = [''];
      var liveId=0;
     
      for (var i = 0; i < $("#liveCount").val(); i++) {
        var ii = parseInt(i) + 1;
        stime = "";//到下一轮清空
        etime = "";
        
        $("#liveStart" + ii).find("input[type='text']").each(function (i) {
          stime += $(this).val();
         

            liveId=$("#liveStart" + ii).attr("liveId");
          
        
        });
        $("#liveEnd" + ii).find("input[type='text']").each(function (i) {
          etime += $(this).val();
        });
        sArr[i] = stime+":00";
        eArr[i] = etime+":00";
        //if (i == 0) {
          // "timeid": "0", "orderid": $("#order").val()
          
            programtimeinfolist.push({
              
              "starthour": sArr[i], "endhour": eArr[i]
              
            });
        
          console.log("时间段:" + JSON.stringify(programtimeinfolist));

      
        if (getNowFormatDate() + " " + sArr[i] >= getNowFormatDate() + " " + eArr[i]) {

          swal("error!", "开始时间不能大于或等于结束时间！", "error");
          return false;
        }
        if (i >= 1) {
          if (getNowFormatDate() + " " + sArr[i] <= getNowFormatDate() + " " + eArr[i - 1]) {

            swal("error!", "第" + ii + "个开始时间不能小于或等于上一个结束时间！", "error");
            return false;
          }
          if (getNowFormatDate() + " " + sArr[i] <= getNowFormatDate() + " " + sArr[i - 1]) {

            swal("error!", "第" + ii + "个时间段开始不能小于或等于上一个时间段！", "error");
            return false;
          }
          if (getNowFormatDate() + " " + eArr[i] <= getNowFormatDate() + " " + eArr[i - 1]) {
            //console.log("mj"+eArr[i])
            swal("error!", "第" + ii + "个时间段结束不能小于或等于上一个时间段！", "error");
            return false;
          }
         
      

        }

      }
  

    }else {
      programtimeinfolist.push(
      //  {"starthour":"", "endhour":""}
      );
      datadd["program"] = ({
        "programPrice": $("#programPrice").val(),
        "programtype": programtype,
        "programid": programid,
        "order_id": orderid,
        "companyid": sessionStorage.getItem("coid"),
        "type": $("#typejm").val(),
        "starttime": $("#starttime").val()+" "+"00:00:00",
        "endtime": $("#endtime").val()+" "+"23:59:59",
        "playtime": $("#playtime").val(),
        "devicetype": $("#devicetype").val(),
        "festivalname": $("#festivalname").val(),
        "isplayvoice": $("#isplayvoice").val(),
        "playtype": $("#playtype").val()
        
  
      });
      console.log("时间"+$("#starttime").val() +" "+$("#timeid").val()+":00")
    }

  //  console.log("时间段:" + JSON.stringify(programtimeinfolist));

    var programzeroinfo = new Array();
    var materialinfo = new Array();
    var j = 0;
    $(".col-md-9").find(".form-inline").each(function (i) {
      if (i > 1) {
        j++;
        //type
        //alert($(this).find("#left").val());
        console.log("left:" + $(this).find("#left").val());

        programzeroinfo.push({
          "companyid": sessionStorage.getItem("coid"),
          "zeroindex": j,
          "devicetype": $("#devicetype").val(),
          "type": $(this).find("#type").val(),
          "left": $(this).find("#left").val(),
          "top": $(this).find("#top").val(),
          "width": $(this).find("#width").val(),
          "high": $(this).find("#high").val(),
          "order_id": $("#order").val()
        });
        i = i - 2;
        var typetext = $("#material li a").eq(i).text();
        var type = 2;
        if (typetext == " 文本") {
          type = 0;
        }
        if (typetext == " 图片") {
          type = 1;
        }


        var path = "";
        var size = "0";
        if (type == 1) {
          var spid = $(this).attr("id").split('_');
          if ($("#program_" + spid[1]).find("img").length == 0) {

            zt = false;
            swal("OMG!", "请检测分区无法上传空图片", "error");
            return false;
          }
          path = ""; size = 0;
        }

        if (type == 2) {
          var spid = $(this).attr("id").split('_');
          if ($("#program_" + spid[1]).find("img").length == 0) {

            zt = false;
            swal("OMG!", "请检测分区无法上传空动画", "error");
            return false;

          }


          var img = $("#gifwidepth").val().split('*');
          //  console.log("gifds"+$("#gifwidepth").val())
          if (parseInt(img[0]) > parseInt($(this).find("#width").val()) || parseInt(img[1]) > parseInt($(this).find("#high").val())) {

            swal("OMG!", "动画不能超过分区宽高,动画尺寸为：" + img[0] + "*" + img[1], "error"); zt = false;
            return false;

          }

          path = ""; size = 0;
        }
        var fontcolor = typeof ($(this).find("#fontcolor").val()) != "undefined" ? $(this).find("#fontcolor").get(0).selectedIndex : 0;
        var backcolor = $(this).find("#backcolor").get(0).selectedIndex;


        if (type == 0) {
          var regtext = new RegExp(/\"/g, "g");
          var fosizeval = $(this).find("#fosizeval").val().replace(regtext, "”");
          var spid = $(this).attr("id").split('_');
          var html = $(this).find("#editor").text();

          if ($(this).find("#texttype").val() == "1" || $(this).find("#texttype").val() == "2") {
            if (html == "") {
              swal("OMG!", "请检测分区文本不能为空", "error");
              zt = false;
              return false;
            }
          } else {
            if ($(this).find("#fosizeval").val() == "") {
              swal("OMG!", "请检测分区文本不能为空", "error");
              zt = false;
              return false;
            }
           
          }

          //alert(html.length);//alert($(this).find("#fosizeval").val().length);


            console.log("电脑字体"+html);
          if (parseInt(html.length) > 200 || parseInt($(this).find("#fosizeval").val().length) > 200) {

            swal("OMG!", "输入内容超过了限制范围", "error"); zt = false;
            return false;
          }

      
          var testsize = $(this).find("#fontsizeadd").find("option:selected").text().split("*");

          if (parseInt($(this).find("#width").val()) < parseInt(testsize[0])) {
            swal("OMG", "分区的宽度不能小于字体的大小！", "error"); zt = false;
            return false;

          }
          if (parseInt($(this).find("#high").val()) < parseInt(testsize[0])) {
            swal("OMG", "分区的高度不能小于字体的大小！", "error"); zt = false;
            return false;

          }
          var imgbase = $("#from_" + spid[1]).find("#imgDataURL").val();

        //  console.log("imgbase:"+spid[1]+":"+$("#program_" + spid[1]).find("#imgDataURL").val());

          var edui32_button_body = $("#from_" + spid[1]).find(".edui-for-fontsize").find(".edui-box").html() + "14px";

          var reg = new RegExp("px", "g");
          // console.log("你"+$("#from_" + spid[1]).find(".edui-for-fontsize").find(".edui-box").html())
          edui32_button_body = edui32_button_body.replace(reg, "");



          if ($(this).find("#texttype").val() != "1") {
          
            imgbase = "";



            if (edui32_button_body == "字号") {

              edui32_button_body = 14;


            }
          } else {

            edui32_button_body = 0;
          }
          //console.log(edui32_button_body);
          var textflag = 0;
          if (parseInt($("#_" + spid[1]).outerHeight()) > parseInt($("#program_" + spid[1]).outerHeight())) {
            textflag = 1;
          }
          console.log(textflag);


         
          //imgbase=imgbase.substr(imgbase.indexOf(',') + 1);
          materialinfo.push({
            "companyid": sessionStorage.getItem("coid"),
            "materialid": "",
            //"zeroindex":j,	model 
            "fontName": $(this).find("#typefaceval option:selected").attr("id"),
            "fontAlign": $(this).find("#alignment").val(),
            "text": $(this).find("#fosizeval").val() == "" ?$(this).find("#editor").html() : fosizeval,
            "type": type,
            "devicetype": $("#devicetype").val(),
            "path": path,
            "size": parseInt(size),
            "model": 1,
            "intype": $(this).find("#intype").val(),
            "inspeed": $(this).find("#inspeed").val(),
            "fontcolor": typeof ($(this).find("#fontcolor").val()) == "undefined" ? 0 : fontcolor == "-1" ? 0 : fontcolor,
            //"fontsize":edui32_button_body,
            "fonteffect": $(this).find("#Dazzle").val(),
            "fontsize": $(this).find("#texttype").val()==0?$(this).find("#fontsizeadd").val():$(this).find(".text-size").find("button").text(),
            "backcolor": backcolor == "-1" ? 0 : backcolor,
            "staytime": $(this).find("#staytime").val(),
            "order_id": $("#order").val(),
            "zeroindex": j,
            "randomFontColor": $(this).find("#randomFontColor").val(),
            "advancedid": $(this).find("#Dazzle").val() != "0" ? 4 : $(this).find("#texttype").val() == "1" ? 3 : 0,
            "imgbase": imgbase,
            "textflag": textflag,
          });

     //     console.log("有值:"+imgbase);
          if (textflag == "0") {
            //   programzeroinfo[i].type=1;
            //   materialinfo[i].type=1;
            //  console.log(programzeroinfo[i].type+":"+ materialinfo[i].type);
          }
        } else if (type == 1) {
          var spid = $(this).attr("id").split('_');
          var _this = this;
          $(this).find(".item").each(function (i) {
            if (typeof ($(this).find("#pathimg").val()) != "undefined") {
              if ($(this).find("#pathimg").val().length > 0) {
                // var imgPath=$(this).attr("src").split(',');
                //imgPath=imgPath[1];
                //imgPath = imgPath.substr(0, imgPath.length - 1); 
                //return;
                // imgPath=imgPath.substr(imgPath.lastIndexOf('.') + 1);
                // if(){
                //  $("#program_"+spid[1]).find("img")
                materialinfo.push({
                  "materialid": "",
                  "companyid": sessionStorage.getItem("coid"),
                  //"zeroindex":j,	model 
                  "text": typeof ($(_this).find("#fosizeval").val()) == "undefined" ? html : fosizeval,
                  "type": type,
                  "devicetype": $("#devicetype").val(),
                  "path": $(this).find("#pathimg").val(),
                  "size": $(this).find("#pathsize").val(),
                  "fileId": $(this).find("#fileId").val(),
                  "model": 1,
                  "intype": $(_this).find("#intype").val(),
                  "inspeed": $(_this).find("#inspeed").val(),
                  "fontcolor": typeof ($(_this).find("#fontcolor").val()) == "undefined" ? 0 : fontcolor,
                  "fontsize": typeof ($(_this).find("#fontsizeadd").val()) == "undefined" ? 0 : $(_this).find("#fontsizeadd").val(),
                  "backcolor": backcolor,
                  "staytime": $(_this).find("#staytime").val(),
                  "order_id": $("#order").val(), "zeroindex": j,
                  //"advancedid":1,
                  //"imgbase":imgbase
                });
              }
            }
          });
        } else {
          var _this = this;
          $(this).find(".item").each(function (i) {
            if (typeof ($(this).find("#pathimggif").val()) != "undefined") {
              if ($(this).find("#pathimggif").val().length > 0) {


                // console.log($(this).find("#staytime").val());
                materialinfo.push({
                  "materialid": "",
                  "companyid": sessionStorage.getItem("coid"),
                  //"zeroindex":j,	model 
                  "text": typeof ($(_this).find("#fosizeval").val()) == "undefined" ? "" : fosizeval,
                  "type": type,
                  "devicetype": $("#devicetype").val(),
                  "path": $(this).find("#pathimggif").val(),
                  "size": $(this).find("#pathgifsize").val(),
                  "fileId": $(this).find("#fileId").val(),
                  "model": 1,
                  "intype": $(_this).find("#intype").val(),
                  "inspeed": $(_this).find("#inspeed").val(),
                  "fontcolor": typeof ($(_this).find("#fontcolor").val()) == "undefined" ? 0 : fontcolor,
                  "fontsize": typeof ($(_this).find("#fontsizeadd").val()) == "undefined" ? 0 : $(_this).find("#fontsizeadd").val(),
                  "backcolor": backcolor,
                  "staytime": $(_this).find("#staytime").val(),
                  "order_id": $("#order").val(), "zeroindex": j
                });
              }
            }
          });
        }
      }

      datadd["programtimeinfolist"] = programtimeinfolist;
      datadd["programzeroinfo"] = programzeroinfo;
      datadd["materialinfo"] = materialinfo;
    });
    //console.log("234:"+JSON.stringify(datadd["materialinfo"]));
    //return;
    //console.log(JSON.stringify(datadd));
    //alert(zt);

    if (zt) {
      if (idjm) {

        console.log(JSON.stringify(datadd));
        //domain.ajaxUrl({
        //    method: 'POST',
        //	url: domain.testUrl+"/Threeinjection/programManagement/programadd",
        //		data:{"programadd":JSON.stringify(datadd),sessionid:sessionStorage.getItem("sid")},
        //data: {sessionid:sessionStorage.getItem("sid")},
        // datatype:"JSON",
        //    success: function (response) {
        console.log(JSON.stringify(datadd));

        $.fn.jqLoading({ height: 100, width: 240, text: "正在保存中，请耐心等待...." });
        $.ajax({
          type: "POST",
          //url: "上传图片接口",
          url: domain.testUrl + "/Threeinjection/programManagement/programadd",
          data: { "programadd": JSON.stringify(datadd), sessionid: sessionStorage.getItem("sid") },
          //视情况将base64的前面字符串data:image/png;base64,删除
          cache: false,
          success: function (response) {
            $.fn.jqLoading("destroy");
            // console.log(response);
            response = JSON.parse(response);
            if (response.code == "200") {
              idjm = false;

              //$("#fsopen").click();
              swal("success!", "保存成功", "success");
              //节目号
              programlist();
              //  alert(programtype);
              //return;
              //  canvas();
              // if(confirm("是否跳转到节目")){

              // }
              //chen,还在改

              setTimeout(function () {
                if (programtype == "0") {

                  // parent.Addtabs.close("tab_101");//关闭新增节目                 
                  //  parent.$("#tab_tab_101 a").click();

                  setTimeout(function () {
                    // window.location.reload('#iftab_101');//刷新本页面
                    programtype = 0;
                    $("#error").html("");
                    zoomsum = 0;
                    //清除节目信息
                    $("#festivalname").val("节目_文本");
                    $("#typejm").val("3");
                    $("#isplayvoice").val("0");
                    $("#playtype").val("0");
                    $("#playtime").prev().text("次数");
                    $("#playtime").val("1")
                    // $("#zoom img:eq(1)").hide();
                    // $("#zoomsum").text("0");
                    $("#program").css("height", sessionStorage.getItem("high")).css("width", sessionStorage.getItem("width"));
                    //清空分区,点击删除的图标
                    $("#material li").each(function (i) {
                      del($(this).find("img:eq(1)"));
                      //$("#materialinfo li a").eq(i).click();
                    });
                    canvas();
                    $("#zoom img").eq(0).click();
                    $(".confirm").click(); //关掉成功提示框
                    parent.Addtabs.add({ 'id': 15, "title": "节目列表", 'url': "?#/page/Program/list" });
                  }, 500);
                  // location.reload();


                  //return;
                } else {
                  programtype = 0;
                  return;
                }

              }, 1000);


            }
          },
          error: function (XMLHttpRequest, textStatus, errorThrown) {
            $.fn.jqLoading("destroy");
            swal("OMG!", "保存失败", "error");
          }
        });
      }
    }

  }
  //保存模板
  var valuejm = "";
  $("#addmb").click(function () {

    //alert($("#programInfomb").html());
    if ($("#programInfomb .col-md-5").length > 20) {
      swal("OMG!", "最多只能添加20个模板", "error");
      return false;
    }
    programtype = 1;

    $("#addjm").click();

    //$("#programtype").val(1);
  });
  var group_programid = "";
  $("#mbdel").click(function () {
    if (valuejm == "") {
      swal("OMG!", "请选择节目模板", "error");
      return;
    }
    valuejm = valuejm.split(':');
    var msg = "确定删除节目模板吗？";
    if (confirm(msg)) {
      $.ajax({
        type: 'POST',
        url: domain.testUrl + "/Threeinjection/programManagement/deleteProgramInfo",
        data: { "programidList": valuejm[0], sessionid: sessionStorage.getItem("sid") },
        success: function (response) {
          response = JSON.parse(response);
          if (response.code == "200") {
            swal("success!", "删除成功", "success");
            listmb(); valuejm = "";
          }
        }
      });
    }
  });
  $("#mbqd").click(function () {
    //    var flag=true;
    //  $("#programInfomb").each(function(i){
    //    console.log("你就"+$("#programInfomb .col-md-5").length)
    //   if($("#programInfomb .col-md-5").length>0){
    if (valuejm == "") {
      //  flag==false;
      swal("OMG!", "请选择节目模板", "error");
      return false;
    }
    //   }else{
    //     flag==false;
    //     console.log("我进来了"+i)
    //    // $("#myModalmb .close").click();
    //   }
    //   console.log("没进判断")
    //  });
    //  if(flag==false){
    //   console.log("我进来了"+i)
    //    return false;
    //  }

    $("#error").html("");
    zoomsum = 0;
    $("#zoom img:eq(1)").hide();
    $("#zoomsum").text("0");
    $("#program").css("height", sessionStorage.getItem("high")).css("width", sessionStorage.getItem("width"));
    canvas();
    //清空分区
    $("#material li").each(function (i) {

      del($(this).find("img:eq(1)"));
      //$("#materialinfo li a").eq(i).click();

    });
    $("#myModalmb .close").click();
    $("#zoomsum").html(0);
    // return;
    valuejm = valuejm.split(":")[0];

    $.ajax({
      type: "POST",
      //url: "上传图片接口",
      url: domain.testUrl + "/Threeinjection/programManagement/queryprogramAllInfo",
      data: { "programid": valuejm, sessionid: sessionStorage.getItem("sid") },
      //视情况将base64的前面字符串data:image/png;base64,删除
      //async:false, 
      success: function (response) {
        canvas();
        // console.log(response);
        var obj = eval("(" + response + ")");

        response = JSON.parse(obj.programInfo);

        var materialid = response[0].protimeinfo;

        group_programid = response[0].group_programid;
        $("#order").val(response[0].order_id);
        $("#festivalname").val(response[0].festivalname);
        $("#devicetype").val(response[0].devicetype);
        $("#typejm").val(response[0].type);
        $("#playtype").val(response[0].playtype);
        $("#isplayvoice").val(response[0].isplayvoice);
        // alert(response[0].playtime);
        $("#playtime").val(response[0].playtime);

        if ($("#playtype").val() == "0") {

          $("#playtime").prev().text("次数");
        } else {
          $("#playtime").prev().text("时长(s)");
        }

       //转换开始日期时间
       var d = new Date(parseInt(response[0].starttime));
       d = d.Format("yyyy-MM-dd hh:mm:ss");
 
       $("#starttime").val(d.substring(0, 10));
 
      // $("#timeid").val(d.substring(10));
 
       var d1 = new Date(parseInt(response[0].endtime));
       d1 = d1.Format("yyyy-MM-dd hh:mm:ss");
       
       $("#endtime").val(d1.substring(0, 10));
       
      // $("#starthour").val(d1.substring(10));

  
         //周期
      var checkArry = response[0].days;
      if(response[0].protimeinfo!="" &&response[0].protimeinfo!==null){
         $("#highTime").click();
       
       var checkArry=response[0].days.toString();
       checkArry=checkArry.substring(1,checkArry.length-1);
       var splitCheck=checkArry.split(',');
       
      // $(".current li input").click();
           for(var k=0;k<splitCheck.length;k++){
 
             $(".current li:eq("+(splitCheck[k]-1)+") input").click();
          }
       
 
       $("#liveCount").val(response[0].protimeinfo.length);
       timeChange();
       //时间段
       for(var j=0;j<response[0].protimeinfo.length;j++){
        // console.log("time:"+response[0].protimeinfo[j].starthour+"-"+response[0].protimeinfo[j].endhour);
        $("#liveStart"+(j+1)).attr("liveId",response[0].protimeinfo[j].id);
           for(var jj=0;jj<2;jj++){
        var hour=((jj+1)%2)==0?response[0].protimeinfo[j].endhour.split(':'):response[0].protimeinfo[j].starthour.split(':');
        var thisid=((jj+1)%2)==0?"#liveEnd":"#liveStart";
 
        $(thisid+(j+1)+" input:eq(0)").val(hour[0]);
        $(thisid+(j+1)+" input:eq(2)").val(hour[1]);
       
           }
       }

      }

        try {
          for (var i = 0; i < response[0].children.length; i++) {
            $("#materialinfo li").eq(response[0].children[i].type).find("a").click();
            var ii = parseInt(i) + 1;
            //alert(ii);
            //	   $("#materialinfo li a")
            //alert(response[0].children[i].type);
            console.log("个数"+i)
            //文字
            $("#from_" + selectid).find("#index").val(ii);
            //  alert(response[0].children[i].type==0);
            if (response[0].children[i].type == 0) {

              $("#program_" + selectid).css("width", response[0].children[i].width + "px");
              $("#program_" + selectid).css("height", response[0].children[i].high + "px");

              $("#program_" + selectid).css("top", response[0].children[i].top + "px");
              $("#program_" + selectid).css("left", response[0].children[i].lef + "px");

              //$("#program_"+selectid).css("overflow","hidden").css("white-space","pre");
              //chen改，预览
              $("#program_" + selectid).css("word-wrap", "break-word").css("word-break", "break-all").css("overflow", "hidden");
              //$("#program_"+selectid).css("left",response[0].children[i].lef+"px");
              var leftwz = $('#program_' + selectid).position().left + "px";
              var reg = new RegExp("px", "g");
              leftwz = leftwz.replace(reg, "");
              $('#program_' + selectid).find("#leftdw").val(leftwz);

              //$("#program_"+selectid).css("font-size",response[0].children[i].children[0].fontsize+"px");
              //$("#program_"+selectid).css("font-size","16px");

              $("#program_" + selectid).css("color", fontcolorvalmb(response[0].children[i].children[0].fontcolor));
              $("#from_" + selectid).find("#left").val(response[0].children[i].lef);

              $("#from_" + selectid).find("#top").val(response[0].children[i].top);

              $("#from_" + selectid).find("#width").val(response[0].children[i].width);

              $("#from_" + selectid).find("#high").val(response[0].children[i].high);
              $("#from_" + selectid).find("#intype").val(response[0].children[i].children[0].intype);

              $("#from_" + selectid).find("#inspeed").val(response[0].children[i].children[0].inspeed);
              //alert(response[0].children[i].children[0].fontcolor);
              $("#from_" + selectid).find("#fontcolor").val(fontcolorvalmb(response[0].children[i].children[0].fontcolor));
              $("#from_" + selectid).find("#fontcolor").parent().show();
              $("#from_" + selectid).find("#fontsizeadd").val(response[0].children[i].children[0].fontsize);
              //alert(response[0].children[i].children[0].fontsize);
              //console.log( $("#from_"+selectid).find("#fontsizeadd").find("option:selected").text());
              var fontsize = $("#from_" + selectid).find("#fontsizeadd").find("option:selected").text().split("*");
              //alert(response[0].children[i]);
              $("#program_" + selectid).css("font-size", fontsize[1] + "px");
              $("#from_" + selectid).find("#backcolor").val(fontcolorvaltow(response[0].children[i].children[0].backcolor));
              // alert(response[0].children[i].children[0].backcolor);
              //alert(response[0].children[i].children[0].fontsize);
              $("#from_" + selectid).find("#staytime").val(response[0].children[i].children[0].staytime);
              
              //alert(response[0].children[i].children[0].type);

              $("#from_" + selectid).find("#type").val(response[0].children[i].children[0].type);



              $("#from_" + selectid).find("#FTPurl").val(response[0].children[i].children[0].FTPurl);
              $("#from_" + selectid).find("#size").val(response[0].children[i].children[0].size);
              $("#from_" + selectid).find("#materialid").val(response[0].children[i].children[0].materialid);

              $("#from_" + selectid).find("#txtpath").val(response[0].children[i].children[0].txtpath);
              console.log("着呢" + response[0].children[i].children[0].advancedid);
              //  $("#from_" + selectid).find("#texttype").val(response[0].children[i].children[0].advancedid);

              //  $("#from_"+selectid).find("#randomFontColor,#Dazzle").parent().show();
              // $("#from_"+selectid).find("#texttype").parent().css("margin-left","-24.8%");

              //电脑字体
              if (response[0].children[i].children[0].advancedid == "1") {
                $("#from_" + selectid).find("#alignment").parent().show();
                //$("#from_"+selectid).find("#typefaceval").parent().css("margin-left","-50%");
                $("#from_" + selectid).find("#texttype").val("0");

                $("#from_" + selectid).find("#typefaceval").val($("#from_" + selectid).find("#typefaceval").find("#" + response[0].children[i].children[0].fontname).val());
                $("#from_" + selectid).find("#Dazzle").parent().css("margin-left", "-24.8%");
                //alert($("#from_"+selectid).find("#"+response[0].children[i].children[0].fontname).val());
              }
              //word 电脑字体
              // alert(response[0].children[i].children[0].advancedid);
              if (response[0].children[i].children[0].advancedid == "3") {
                // $("#from_"+selectid).find("#alignment").parent().show();
                //$("#from_"+selectid).find("#fontcolordiv,#fontsizediv,#fosizeval").hide();
                $("#from_" + selectid).find("#alignment").parent().hide();
                $("#from_" + selectid).find("#typefaceval").parent().hide();
                $("#from_" + selectid).find("#randomFontColor").parent().hide();
                $("#from_" + selectid).find("#Dazzle").parent().hide();
                $("#from_" + selectid).find("#fontsizeadd").parent().hide();
                $("#from_" + selectid).find("#texttype").val("1");
                $("#from_" + selectid).find("#text_pic_form").show();
                $("#from_" + selectid).find("#fosizeval").hide();
                // var text = response[0].children[i].children[0].text.toString().replace("↵", "\n")
                // $("#from_" + selectid).find("#editor").val(text); 
                $("#from_" + selectid).find("#text_pic_form").show();
                $("#from_" + selectid).find("#text_pic_form").find(".text-size button:eq(0)").text(response[0].children[i].children[0].fontsize);
                init();//电脑字体
                Canvasfont();
              }
              //炫彩效果
              if (response[0].children[i].children[0].advancedid == "2") {
                $("#from_" + selectid).find("#typefaceval").parent().hide();
                $("#from_" + selectid).find("#Dazzle").html("<option value='" + response[0].children[i].children[0].fonteffect + "'>炫彩效果" + response[0].children[i].children[0].fonteffect + "</option>");
                $("#from_" + selectid).find("#randomFontColor").parent().hide();
                $("#from_" + selectid).find("#Dazzle").parent().css("margin-left", "");
              }
              //炫彩字体
              if (response[0].children[i].children[0].advancedid == "4") {
                $("#from_" + selectid).find("#alignment").parent().hide();
                //隐藏颜色
                $("#from_" + selectid).find("#fontcolor").parent().hide();
                $("#from_" + selectid).find("#typefaceval").val(response[0].children[i].children[0].advancedid);
                $("#from_" + selectid).find("#Dazzle").parent().show();
                $("#from_" + selectid).find("#Dazzle").html("<option value='" + response[0].children[i].children[0].fonteffect + "'>炫彩效果" + response[0].children[i].children[0].fonteffect + "</option>")
                $("#from_" + selectid).find("#Dazzle").parent().css("margin-left", "");
              }

              if (response[0].children[i].children[0].randomFontColor != "0") {
                $("#from_" + selectid).find("#randomFontColor").val(response[0].children[i].children[0].randomFontColor);
                $("#from_" + selectid).find("#Dazzle").parent().hide();
                $("#from_" + selectid).find("#randomFontColor").parent().css("margin-left", "-24.8%");
              }

              if (response[0].children[i].children[0].fontcolor == "2" || response[0].children[i].children[0].fontcolor == "6") {

                $('#from_' + selectid).find("textarea").css("color", "black");
              } else {
                // console.log("没进来"+response[0].children[i].children[0].fontcolor)
                $('#from_' + selectid).find("textarea").css("color", $('#from_' + selectid).find("#fontcolor").val());
              }
              $("#from_" + selectid).find("#txt").val(response[0].children[i].children[0].text);
              // var regText = new RegExp(/\“/g, "g");
             // var text = response[0].children[i].children[0].text.toString().replace("↵", "\n");
              //$("#program" + selectid).val(text);
              $("#from_" + selectid).find("#fosizeval").val(text);
              console.log("就看见" + text);

              //模板保存的点阵的字体
              // $("#program_"+selectid).html("<div  style=width:inherit;font-family:'"+ $('#from_' + selectid).find("#typefaceval").val()+"'></div>"+"<input type='hidden' id='imgDataURL'><input type='hidden' id='leftdw' value="+$("#program_"+selectid).find("#leftdw").val()+">"); 

              $("#from_" + selectid).find("#alignment").val(response[0].children[i].children[0].fontalign);
              if ($("#from_" + selectid).find("#alignment").val() == "0") {
                $("#program_" + selectid).css("display", "");
                $("#program_" + selectid).css("align-items", "");
              }
              if ($("#from_" + selectid).find("#alignment").val() == "2") {
                $("#program_" + selectid).css("display", "grid");
                $("#program_" + selectid).css("align-items", "flex-end");
              }
              if ($("#from_" + selectid).find("#alignment").val() == "1") {

                $("#program_" + selectid).css("display", "grid");
                $("#program_" + selectid).css("align-items", "center");

              }

              // $("#program_" + selectid).append(response[0].children[i].children[0].text);
              new ZResize({
                stage: "#program", //舞台 
                item: '#program_' + selectid, //可缩放的类名 
              });
            }
            // console.log(response);
            //图片
            if (response[0].children[i].type == 1) {
              //partitioncz();
              $("#program_" + selectid).css("width", response[0].children[i].width + "px");
              $("#program_" + selectid).css("height", response[0].children[i].high + "px");

              $("#program_" + selectid).css("top", response[0].children[i].top + "px");
              $("#program_" + selectid).css("left", response[0].children[i].lef + "px");

              $("#program_" + selectid).css("color", fontcolorvaltow(response[0].children[i].children[0].fontcolor));

              $("#from_" + selectid).find("#left").val(response[0].children[i].lef);
              $("#from_" + selectid).find("#top").val(response[0].children[i].top);
              $("#from_" + selectid).find("#width").val(response[0].children[i].width);
              $("#from_" + selectid).find("#high").val(response[0].children[i].high);


              $("#from_" + selectid).find("#intype").val(response[0].children[i].children[0].intype == "0" ? 1 : response[0].children[i].children[0].intype);
              $("#from_" + selectid).find("#inspeed").val(response[0].children[i].children[0].inspeed);


              $("#from_" + selectid).find("#backcolor").val(fontcolorvaltow(response[0].children[i].children[0].backcolor));
              $("#from_" + selectid).find("#staytime").val(response[0].children[i].children[0].staytime);
              $("#from_" + selectid).find("#type").val(response[0].children[i].children[0].type);



            }
            //动画
            if (response[0].children[i].type == 2) {

              $("#program_" + selectid).css("width", response[0].children[i].width + "px");
              $("#program_" + selectid).css("height", response[0].children[i].high + "px");

              $("#program_" + selectid).css("top", response[0].children[i].top + "px");
              $("#program_" + selectid).css("left", response[0].children[i].lef + "px");

              $("#program_" + selectid).css("color", fontcolorvaltow(response[0].children[i].children[0].fontcolor));

              $("#from_" + selectid).find("#left").val(response[0].children[i].lef);
              $("#from_" + selectid).find("#top").val(response[0].children[i].top);
              $("#from_" + selectid).find("#width").val(response[0].children[i].width);
              $("#from_" + selectid).find("#high").val(response[0].children[i].high);


              $("#from_" + selectid).find("#intype").val(response[0].children[i].children[0].intype == "0" ? 1 : response[0].children[i].children[0].intype);
              $("#from_" + selectid).find("#inspeed").val(response[0].children[i].children[0].inspeed);


              $("#from_" + selectid).find("#backcolor").val(fontcolorvaltow(response[0].children[i].children[0].backcolor));
              $("#from_" + selectid).find("#staytime").val(response[0].children[i].children[0].staytime);
              $("#from_" + selectid).find("#type").val(response[0].children[i].children[0].type);

              //partitioncz();
              //picturegif(response,i);;$("#from_"+selectid).find("#texttype").parent().hide();
            } else {

              //  console.log($("#from_"+selectid).find("#txtpath").val());
              if (sessionStorage.getItem("type") == "0" || sessionStorage.getItem("type") == "1") {
                $("#texttype option[value='1']").remove();
              }
              var _uat = navigator.userAgent;
              if (_uat.indexOf("Firefox") > 0) {
                $("#texttype option[value='1']").remove()

                $("#container" + selectid).hide();
                //#fontcolordiv
                $("#fontsizediv,#fosizeval").show();

              }
            }

            var material_index = response[0].children[i].children[0].material_index;
            //alert(material_index);
            var zeroindex = response[0].children[i].zeroindex;
          }
          //partitioncz();
          setTimeout(function () {

            $("#error").html("");
            $("#material li").each(function (i) {
              //alert($("#from_"+$(this).attr("id")).find("#txtpath").val());
              var _this = $(this).attr("id");
              //$("#from_"+$(this).attr("id")).find("#texttype").attr("disabled",true);
              if ($("#from_" + $(this).attr("id")).find("#type").val() == "0") {

                if ($("#from_" + $(this).attr("id")).find("#txtpath").val() != "" && $("#from_" + $(this).attr("id")).find("#texttype").val() == "0") {
                  //$("#from_"+selectid)
                  //console.log($(this).attr("id"));

                  $("#from_" + _this).find("#texttype").val(0);
                  $.ajax({
                    type: 'POST',
                    url: domain.testUrl + "/Threeinjection/programManagement/readTxTFile",
                    data: { "txtpath": $("#from_" + $(this).attr("id")).find("#txtpath").val(), sessionid: sessionStorage.getItem("sid") },

                    success: function (response) {

                      // console.log($(this).attr("id")).find("#txtpath").val();
                      // alert($("#container"+selectid).html());


                      var html = response;



                      //  $("#program_"+_this).html("<div  style=width:inherit;font-family:'"+ $('#from_' + _this).find("#typefaceval").val()+"'>"+html+"</div>"+"<input type='hidden' id='imgDataURL'><input type='hidden' id='leftdw' value="+$("#program_"+_this).find("#leftdw").val()+">"); 

                      $("#program_" + _this).css("line-height", "1");
                      //"container"+_this
                      $('#container' + _this).hide();
                      //$("#from_"+_this).find("#fosizeval").val();
                      $("#from_" + _this).find("#fosizeval").show();
                      //  $("#from_" + _this).find("#fontcolordiv").show();
                      $("#from_" + _this).find("#fontsizediv").show();
                      //   $("#from_"+_this).find("#fosizeval").val(html);
                      new ZResize({
                        stage: "#program", //舞台 
                        item: '#program_' + _this, //可缩放的类名 
                      });
                    }
                  });
                } else {

                  // UE.getEditor('container'+_this).setContent(""+$("#from_"+$(this).attr("id")).find("#txt").val()+"",true);
                  if ($("#from_" + $(this).attr("id")).find("#texttype").val() == "1" || $(this).val() == "2") {
                    $.ajax({
                      type: 'POST',
                      url: domain.testUrl + "/Threeinjection/programManagement/readTxTFile",
                      data: { "txtpath": $("#from_" + $(this).attr("id")).find("#txtpath").val(), sessionid: sessionStorage.getItem("sid") },

                      success: function (response) {
                        //   alert(response);   
                        // console.log($(this).attr("id")).find("#txtpath").val();
                        // alert($("#container"+selectid).html());


                        var html = response;


                        //#fontcolordiv,
                        $("#fontsizediv,#fosizeval").hide();
                        $("#program_" + selectid).css("line-height", "");
                        $("#from_" + selectid).find("#fosizeval").val("");

                        //  console.log(html);

                        // UE.getEditor('container' + _this).setContent(html, false);
                        // var html = UE.getEditor("container" + _this).getContent();
                        // $("#program_" + _this).html("<div style='width:inherit;'>" + html + "</div>" + "<input type='hidden' id='imgDataURL'><input type='hidden' id='leftdw' value=" + $("#program_" + _this).find("#leftdw").val() + ">");
                        // $("#program_" + _this).find("p:eq(0)").css("line-height", "1");

                        // // $("#program_"+_this).css("color","rgb(255, 0, 0)").css("white-space","pre").css("overflow","hidden");
                        // $("#program_" + _this).css("color", "red").css("word-wrap", "break-word").css("word-break", "normal");

                      }

                    });
                  } else {


                  }
                }
              }
            });
            $("#material li").eq($("#material li").length - 1).click();
            $("#error").html("");

            setTimeout(function () {

              $("#zoom img").eq(0).click();

            }, 500);


            overlap();
          }, 1000);

        } catch (ex) {

        }
      }
    });
  });
  //选择模板
  var selectmbindex = -1;
  $("#selectmb").click(function () {
    listmb();
    ///programManagement/queryProgramTemplate
  });
  window.listmb = function () {
    $("#programInfomb").html("");
    $.ajax({
      type: 'POST',
      url: domain.testUrl + "/Threeinjection/programManagement/queryProgramTemplate",
      data: { sessionid: sessionStorage.getItem("sid"), "companyId": sessionStorage.getItem("coid") }, success: function (response) {
        // console.log(response);
        var data = JSON.parse(response);
        response = data;
        var programTemplate = JSON.parse(response.programTemplate);
        //alert(response.programTemplate.length);
        var programid = "";
        if (programTemplate.length == 0) {
          var no = "<span style='font-size:18px;color:red;'>暂无模板数据</span>";
          $("#programInfomb").css("display", "flex").css("align-items", "center").css("justify-content", "center").css("flex-direction", "column");
          $("#programInfomb").html(no);
        }
        for (var j = 0; j < programTemplate.length; j++) {
          data = programTemplate[j].programInfo;
          programid = programTemplate[j].programid;
          var festivalname = programTemplate[j].festivalname;
          var div = "";
          for (var i = 0; i < data.length; i++) {
            var type = data[i].type == "0" ? "<img src='static/img/wmb.png'  class='img-rounded'/>" : data[i].type == "1" ? "<img src='static/img/tmb.png'  class='img-rounded'/>" : "<img src='static/img/dmb.png'  class='img-rounded'/>";

            if (parseInt(data[i].width) < 24 || parseInt(data[i].high) <= 15) {
              type = "<img src='static/img/tmb.png' style='width:" + data[i].width + "px;height:" + (parseInt(data[i].high) + parseInt(4)) + "px' class='img-rounded'/>";

            }

            // type = "<span>" + type + "</span>";
            // type="<img src='static/img/wmb.png'  class='img-rounded'/>"
            div += "<div style='  color: red;font-size: 16px;  display: flex;align-items: center;justify-content: center; flex-direction: column;position: absolute;border: 1px dashed rgb(255, 255, 255);width:" + data[i].width + "px;height:" + data[i].high + "px;left:" + data[i].lef + "px;top:" + data[i].top + "px;'>" + type + "</div>";
          }
          var w = parseInt(sessionStorage.getItem("width")) + 4;
          var html = "<div class='col-md-5' style='margin-bottom:10px;margin-left: 0px;border: 2px dashed  #ccc!important;padding-right: 0px;padding-left: 0px;margin-right: 10px;width:" + w + "px;text-align: center;'><span style='font-size: 16px;color: blue; font-weight: bold;'>" + programid + ":" + festivalname + "</span><br><div class='col-md-4' style='padding-right: 0px;padding-left: 0px;background-color: black;width:" + sessionStorage.getItem("width") + "px;height:" + sessionStorage.getItem("high") + "px;padding-right: 10px; padding-left: 0px;'>" + "<div style=''>" + div + "</div></div></div>";
          $("#programInfomb").append(html);
          if (selectmbindex != -1) {
            $("#programInfomb").find(".col-md-5:eq(" + selectmbindex + ")").css("border", "2px dashed  red");
          }
        }
        $("#programInfomb").find(".col-md-5").click(function () {
          //  $("#programInfomb").find(".col-md-5").css("border","2px dashed #ccc");
          var idd = $("#programInfomb").find(".col-md-5");
          var pr = document.getElementById("programInfomb");
          var cddiv = document.getElementsByClassName("col-md-5");
          for (var l = 0; l < cddiv.length; l++) {
            cddiv[l].style.backgroundColor = "";
          }
          var id = this;
          id.style.backgroundColor = "red";
          selectmbindex = $(this).index();
          valuejm = $(this).find("span:eq(0)").text();
        });
      }
    });
  }
  listmb();
  $("#addjm").click(function () {


    if (programtype != 1) {

      programtype = 0;
    }
    var text = $("")

    setTimeout(function () {
      basesumval()
    }, 200);
  });
  $("#addjm2").click(function () { addjm(); });
  //预览图片 
  window.fileChange = function (ths) {
  };
  //显示日期插件
  $('.date_picker').date_input();
  $("body").removeAttr("style");
  //$("body").css("overflow-x","hidden");
});
var basesum = 0;
//生成图片
window.basesumval = function (ths) {
  var programsum = $("#program .transparent_class").length;
  //for(var i=0;i<zoomsum;i++){
  //  $("#zoom img").eq(1).click();
  // $("#zoomsum").text("0");
  //}
  if (programsum == basesum) {
    idjm = true;
   // xywhinputval();
    setTimeout(function () {
      addjm();
    }, 800);
    // $("#addjm2").click();
    console.log("EDN");
    basesum = 0;
    return;
  }

  var fromid = $("#program .transparent_class").eq(basesum).attr("id").split('_'); var fromid = $("#program .transparent_class").eq(basesum).attr("id").split('_');
  if ($("#from_" + fromid[1]).find("#type").val() == "0") {
    var restfq = false;
    if ($("#zoomsum").text() != "0") {
      // restfq=true;
      //Restorefq($("#program .transparent_class").eq(basesum),0);
    }

    $("#_" + $("#material li").eq(basesum).attr("id")).find("p:eq(0)").css("line-height", "");
    $("#" + $("#program .transparent_class").eq(basesum).attr("id")).find("p:eq(0)").css("line-height", "");

    $("#" + $("#program .transparent_class").eq(basesum).attr("id")).find(".resize-panel").remove();
    //console.log($("#_"+$("#material li").eq(basesum).attr("id")).outerHeight());
    var w = $("#" + $("#program .transparent_class").eq(basesum).attr("id")).outerHeight();
    var jpgpng = 0;
    if (parseInt($("#_" + $("#material li").eq(basesum).attr("id")).outerHeight()) > parseInt(w)) {
      jpgpng = 1;
      $("#" + $("#program .transparent_class").eq(basesum).attr("id")).css("height", $("#_" + $("#material li").eq(basesum).attr("id")).outerHeight() + "px");
    }
    sessionStorage.setItem("programfq", $("#program .transparent_class").eq(basesum).attr("id"));


    $("#" + $("#program .transparent_class").eq(basesum).attr("id")).css("border", '');
   
        $("#" + $("#program .transparent_class").eq(basesum).attr("id")).css("border", '2px dashed rgb(255, 255, 255)');
       // fullQuality = canvas.toDataURL("image/png", 1);
        //  http://192.168.1.135:1000/web/JSAPI.ashx

        // $.ajax({
        // url: "http://192.168.1.135:1000/web/JSAPI.ashx",
        //   type: "post",
        //dataType: "json",
        // data: {"base64":fullQuality},
        // success: function(data){

        // }
        // });
        $("#program_" + fromid[1]).find("p:eq(0)").css("line-height", "1");
        //  console.log(fullQuality);
        // $("#festivalname").val(fullQuality);
       // $("#program .transparent_class").eq(basesum).find("#imgDataURL").val(fullQuality);
        new ZResize({
          stage: "#program", //舞台 
          item: "#" + $("#program .transparent_class").eq(basesum).attr("id"), //可缩放的类名 
        });

        //console.log("#"+$("#program .transparent_class").eq(basesum).attr("id"));
       
     
        // if (restfq) {
        //   Restorefq($("#program .transparent_class").eq(basesum), 1);
        // }
        basesum++;
        basesumval();
    
  } else {
    basesum++;
    basesumval();
  }
};
//生成GUID的算法
window.uuid = function () {
  var s = [];
  var hexDigits = "0123456789abcdef";
  for (var i = 0; i < 36; i++) {
    s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
  }
  s[14] = "4";  // bits 12-15 of the time_hi_and_version field to 0010
  s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);  // bits 6-7 of the clock_seq_hi_and_reserved to 01
  s[8] = s[13] = s[18] = s[23] = "-";
  var uuid = s.join("");
  return uuid;
}

function getNowFormatDate() {
  var date = new Date();
  var seperator1 = "-";
  var year = date.getFullYear();
  var month = date.getMonth() + 1;
  var strDate = date.getDate();
  if (month >= 1 && month <= 9) {
    month = "0" + month;
  }
  if (strDate >= 0 && strDate <= 9) {
    strDate = "0" + strDate;
  }
  var currentdate = year + seperator1 + month + seperator1 + strDate;
  return currentdate;
}

Date.prototype.Format = function (fmt) {
  //author:wangweizhen
  var o = {
    "M+": this.getMonth() + 1,                 //月份   
    "d+": this.getDate(),                    //日
    "h+": this.getHours(),                   //小时   
    "m+": this.getMinutes(),                 //分   
    "s+": this.getSeconds(),                 //秒   
    "q+": Math.floor((this.getMonth() + 3) / 3), //季度   
    "S": this.getMilliseconds()             //毫秒   
  };
  if (/(y+)/.test(fmt))
    fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt))
      fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  return fmt;
}

window.fontcolorvalmb = function (val) {
  var fontcolor = "";
  switch (val) {

    case "0":
      fontcolor = "red";
      break;
    case "1":
      fontcolor = "green";
      break;
    case "2":
      fontcolor = "yellow";
      break;
    case "3":
      fontcolor = "blue";
      break;
    case "4":
      fontcolor = "purple";
      break;
    case "5":
      fontcolor = "cyan";
      break;
    case "6":
      fontcolor = "white";
      break;
  };

  return fontcolor;
}
window.fontcolorval = function (val) {
  var fontcolor = "";
  switch (val) {
    case "#000000":
      fontcolor = 0;
      break;
    case "#FF0000":
      fontcolor = 1;
      break;
    case "#00FF00":
      fontcolor = 2;
      break;
    case "#0000FF":
      fontcolor = 3;
      break;
    case "#C0C0C0":
      fontcolor = 4;
      break;
    case "#FFFFFF":
      fontcolor = 5;
      break;
  };
  return fontcolor;
}
window.fontcolorvaltow = function (val) {
  var fontcolor = "";
  switch (val) {
    case "0":
      fontcolor = "black";
      break;
    case "1":
      fontcolor = "red";
      break;
    case "2":
      fontcolor = "green";
      break;
    case "3":
      fontcolor = "yellow";
      break;
    case "4":
      fontcolor = "blue";
      break;
    case "5":
      fontcolor = "purple";
      break;
    case "6":
      fontcolor = "cyan";
      break;
    case "7":
      fontcolor = "white";
      break;
  };
  return fontcolor;
}
//判断2个div是否有交集,判断时以obj1作为固定的obj2作为移动的
window.divcheck = function (a, b) {
  var ax = a.offsetLeft;
  var ay = a.offsetTop;
  var aw = a.offsetWidth;
  var ah = a.offsetHeight;
  var bx = b.offsetLeft;
  var by = b.offsetTop;
  var bw = b.offsetWidth;
  var bh = b.offsetHeight;
  return (ax + aw > bx && ax < bx + bw && ay + ah > by && ay < by + bh);
}
window.onblurdiv = function () {

  //  console.log("");
  if ($("#from_" + selectid).find("#texttype").val() == "0") {


    return false;

  }
  // 
  if ($("#program .transparent_class").length > 0) {



    $('#splitscreen').animate({ 'scrollTop': 0 }, 0);
    var idonblur = $("#material li[style]").attr("id");
    //var html=UE.getEditor("container"+selectid).getContent();

    var html = $("#from_" + idonblur).find("#fosizeval").val();
    if ($("#from_" + idonblur).find("#texttype").val() == "1") {
      html = UE.getEditor("container" + idonblur).getContent();
    }


    //if(){
    //texttype
    // }
    //预览
    $("#program_" + idonblur).html("<input type='hidden' id='imgDataURL'><input type='hidden' id='leftdw' value=" + $("#program_" + idonblur).find("#leftdw").val() + ">");
    $("#program_" + idonblur).find("p:eq(0)").css("line-height", "1");
    //$("#program_"+idonblur).css("white-space","pre").css("overflow","hidden");
    //预览样式，避免长数字自动换行
    $("#program_" + idonblur).css("word-wrap", "break-word").css("word-break", "break-all");
    //var content = document.getElementById("program_"+selectid);
    //   $.fn.jqLoading({ height: 100, width: 240, text: "正在生成图片...." }); 
    $("#_" + selectid).remove();
    $("body").append("<div id=_" + selectid + " style='width:" + $("#program_" + selectid).outerWidth() + "px;height:auto'>" + $("#program_" + selectid).html() + "<div>");
    $("#_" + selectid).css("word-wrap", "break-word").css("word-break", "break-all").css("border", "2px dashed rgb(255, 255, 255)");
    //.css("line-height",0.96);
    $("#_" + selectid).hide();


    $("#program_" + selectid).find(".resize-panel").remove();
    //console.log($("#_"+$("#material li").eq(basesum).attr("id")).outerHeight());
    var w = $("#program_" + selectid).outerHeight();
    if (parseInt($("#_" + selectid).outerHeight()) > parseInt(w)) {

      //$("#program_"+selectid).css("height",$("#_"+selectid).outerHeight()+"px");
    }
    //$(".transparent_class").each(function(i){
    //new ZResize({ 
    //stage: "#program", //舞台 
    //item: $(this), //可缩放的类名 
    //});
    //});
    //字体放大
    // Fontmax();


    //x,y w,h输入框重新赋值
    //xywhinputval();
    //电脑字体
    if ($("#material #"+selectid+ " a").text().trim() == "文本"){
      if($("#from_" + selectid).find("#texttype").val() == 1){
           Canvasfont();
      }
    }
   
  
  }


}
//x,y w,h输入框重新赋值
function xywhinputval() {
  $(".transparent_class").each(function (i) {
    var id = $(this).attr("id");
    var reg = new RegExp("px", "g");
    id = id.split("_")[1];
    var zoomsum = $("#zoomsum").text();
    if (zoomsum != "0") {
      var sumpx = parseInt(zoomsum) * 2;
      var left = $(this).css("left").replace(reg, "");
      if (left == "auto") {
        left = 0;
      }
      var top = $(this).css("top").replace(reg, "");
      if (top == "auto") {
        top = 0;
      }

      left = parseInt(left) / sumpx;
      top = parseInt(top) / sumpx;
      //  alert(left);


      $("#from_" + id).find("#left").val(parseInt(left));
      $("#from_" + id).find("#top").val(parseInt(top));
      // console.log($(this).outerWidth());
      var w = parseInt($(this).outerWidth()) / sumpx;
      var h = parseInt($(this).outerHeight()) / sumpx;
      $("#from_" + id).find("#high").val(parseInt(h));
      $("#from_" + id).find("#width").val(parseInt(w));
      //div1Height =parseInt(div1.height()),  
      // div2Height =parseInt(div2.outerHeight()),  
      // var left=$("") 
    } else {
      var left = $(this).css("left").replace(reg, "");
      if (left == "auto") {
        left = 0;
      }
      var top = $(this).css("top").replace(reg, "");
      if (top == "auto") {
        top = 0;
      }

      $("#from_" + id).find("#left").val(parseInt(left));
      $("#from_" + id).find("#top").val(parseInt(top));
      var w = parseInt($(this).outerWidth());
      var h = parseInt($(this).outerHeight());
      $("#from_" + id).find("#high").val(parseInt(h));
      $("#from_" + id).find("#width").val(parseInt(w));
    }
  });
}
//分区是否重叠
function overlapdiv(obj1, obj2) {
  var obj1top = parseInt($(obj1).css("top"));
  var obj1left = parseInt($(obj1).css("left"));
  var obj1width = parseInt($(obj1).width());
  var obj1height = parseInt($(obj1).height());
  var obj2top = parseInt($(obj2).css("top"));
  var obj2left = parseInt($(obj2).css("left"));
  var obj2width = parseInt($(obj2).width());
  var obj2height = parseInt($(obj2).height());
  if ((obj2top + obj2height < obj1top) || (obj2top > obj1top + obj1height) || (obj2left + obj2width < obj1left) || (obj2left > obj1left + obj1width)) {
    // console.log(123);
    return false;
  }
  else {
    console.log(456);
    return true;
  }
}
//分区重叠提醒
window.overlap = function () {
  $("#error").html("");
  if ($("#material li").length > 1) {
    var sum = $(".transparent_class").length - 1;
    $(".transparent_class").each(function (i) {

      var ii = i; var overlap = true;
      if ($(".transparent_class").length > 1) {
        $(".transparent_class").each(function (i) {
          $(".transparent_class").eq(ii).css("border", "2px dashed rgb(255, 255, 255)");
          if (ii != i) {
            if (overlapdiv($(".transparent_class").eq(ii), $(".transparent_class").eq(i))) {
              $(".transparent_class").eq(i).css("border", "2px dashed red");
              $("#error").html("分区不能重叠");
              overlap = false;
              return false;
            }
          }
        });
      } else if ($(".transparent_class").length == 1) {
        $(".transparent_class").eq(ii).css("border", "rgb(255, 255, 255)");
        if (overlapdiv($(".transparent_class").eq(ii), $(".transparent_class").eq(1))) {
          $(".transparent_class").eq(ii).css("border", "2px dashed red");
          overlap = false;
          $("#error").html("分区不能重叠");
          return false;

        }
      }
      if (!overlap) {
        //swal("OMG!", "分区不能重叠", "error");
        return false;
      }
    });
  }
  if (!overlap) {
    return;
  }
}
//字体放大
// function Fontmax() {
//   //遍历所有分区
//   $(".transparent_class").each(function (i) {
//     var id = $(this).attr("id");
//     id = id.split("_")[1];
//     if ($('#from_' + id).find("#texttype").val() == 1) {
//       var html = UE.getEditor("container" + id).getContent();
//       //预览

//       $("#program_" + id).html("<input type='hidden' id='imgDataURL'><input type='hidden' id='leftdw' value=" + $("#program_" + id).find("#leftdw").val() + ">");
//       $("#program_" + id).find("p:eq(0)").css("line-height", "1");
//       //chen改预览
//       $("#program_" + id).css("word-wrap", "break-word").css("word-break", "break-all");
//       $("#program_" + id).css("font-size", '');
//       //复制隐藏div
//       $("#_" + id).remove();
//       $("body").append("<div id=_" + id + " style='width:" + $("#program_" + id).outerWidth() + "px;height:auto'>" + $("#program_" + id).html() + "<div>");
//       $("#_" + selectid).css("word-wrap", "break-word").css("word-break", "break-all").css("border", "2px dashed rgb(255, 255, 255)");
//       $("#_" + id).hide();
//       //字体放大
//       if (zoomsum > 0) {
//         $("#program_" + id + " div").find("p").each(function (i) {
//           console.log(i);
//           spanan(this);
//         });
//       }
//     } else {
//       $("#program_" + id).css("color", $("#from_" + id).find("#fontcolor").val());
//     }
//     new ZResize({
//       stage: "#program", //舞台 
//       item: $(this), //可缩放的类名 
//     });

//   });
// }
window.spanan = function (thi) {
  var reg = new RegExp("px", "g");
  $(thi).children("span").each(function () {
    var px = $(this).css("font-size");
    px = px.replace(reg, "");
    var sumpx = zoomsum * 2;
    px = px * sumpx;
    $(this).css("font-size", px + "px");
    $(this).children("span").each(function (i) {
      var px = $(this).css("font-size");
      px = px.replace(reg, "");
      var sumpx = zoomsum * 2;
      px = px * sumpx;
      $(this).css("font-size", px + "px");
      spanan(this);
    });
  });
}
//字体缩小
function Fontmin(thi) {

  //遍历所有分区
  $(thi).each(function (i) {
    var id = $(thi).attr("id");
    id = id.split("_")[1];
    if ($('#from_' + id).find("#texttype").val() == 1) {

      //字体缩小
      if (zoomsum > 0) {
        $("#program_" + id + " div").find("p").each(function (i) {
          //console.log(i);
          spananmin(this);
        });
      }
    } new ZResize({
      stage: "#program", //舞台 
      item: $(this), //可缩放的类名 
    });
  });
}
//缩小放大修改文字大小
window.spananmin = function (thi, sta) {
  var reg = new RegExp("px", "g");
  $(thi).children("span").each(function () {
    var px = $(this).css("font-size");
    px = px.replace(reg, "");
    var sumpx = zoomsum * 2;
    if (sta == "0") {
      px = px / sumpx;
    } else {
      px = px * sumpx;
    }
    $(this).css("font-size", px + "px");
    $(this).children("span").each(function (i) {
      var px = $(this).css("font-size");
      px = px.replace(reg, "");
      var sumpx = zoomsum * 2;
      if (sta == "0") {
        px = px / sumpx;
      } else {
        px = px * sumpx;
      }
      $(this).css("font-size", px + "px");
      spananmin(this, sta);
    });
  });
}
//还原分区大小
window.Restorefq = function (thi, sta) {

  if (zoomsum > 0) {
    var sumpx = zoomsum * 2;
    //遍历所有分区
    $(thi).each(function (i) {
      var w = parseInt($(thi).eq(i).css("width"));
      if (sta == 0) {
        $(thi).eq(i).css("width", parseInt($(thi).eq(i).css("width")) / sumpx);
        $(thi).eq(i).css("height", parseInt($(thi).eq(i).css("height")) / sumpx);
      } else {
        $(thi).eq(i).css("width", parseInt($(thi).eq(i).css("width")) * sumpx);
        var h = parseInt($(thi).eq(i).css("height")) * sumpx;
        //alert(h);
        $(thi).eq(i).css("height", h + "px");
      }
      //x和y轴移动
      if (parseInt($(thi).eq(i).css("left")) > 0) {
        if (sta == 0) {
          var left = parseInt($(thi).eq(i).css("left")) / sumpx;
          $(thi).eq(i).css("left", left);
        } else {
          var left = parseInt($(thi).eq(i).css("left")) * sumpx;
          $(thi).eq(i).css("left", left);
        }
      }
      if (parseInt($(thi).eq(i).css("top")) > 0) {
        if (sta == 0) {
          var top = parseInt($(thi).eq(i).css("top")) / sumpx;
          $(thi).eq(i).css("top", top);
        } else {
          var top = parseInt($(thi).eq(i).css("top")) * sumpx;
          $(thi).eq(i).css("top", top);
        }
      }
      var id = $(thi).attr("id").split("_")[1];
      if (zoomsum > 0) {
        $("#_" + id).css("width", parseInt(w) / sumpx);
      } else {
        $("#_" + id).css("width", parseInt(w) * sumpx);
      }
      if ($("#from_" + id).find("#type").val() == "0") {
        if ($('#from_' + id).find("#texttype").val() == 0) {
          var reg = new RegExp("px", "g");
          var size = $('#from_' + id).find("#fontsizeadd").find("option:selected").text().replace(reg, "");
          size = size.split("*")[0];
          $("#program_" + id).css("font-size", size + "px");
          if (zoomsum > 0) {
            var zoomsumval = 0;
            if (sta == 0) {
              zoomsumval = size / sumpx;
            } else {

              zoomsumval = size * sumpx;
            }
            $("#program_" + id).css("font-size", zoomsumval + "px");
            //$("#_"+id).css("",);
          }
        } else {
          // alert(123);
          $(thi).find("p").each(function (i) {
            spananmin(this, sta);
          });
        }
        $("#_" + id).html($(thi).html());
        $("#_" + id).css("border", "2px dashed rgb(255, 255, 255)");
      }
    });
  }
};
//分区位置是否超出
window.Zonexy = function (div2, pd) {

  //console.log("test");
  try {
    var div1 = $("#program");
    var div1Width = parseInt(div1.width()),
      //console.log(div1Width);
      div2Width = parseInt(div2.outerWidth()),
      div1Height = parseInt(div1.height()),
      div2Height = parseInt(div2.outerHeight()),
      div1Left = parseInt($(div1).css("left")),
      div2Left = parseInt($(div2).css("left")),
      div1Top = parseInt($(div1).css("top")),
      div2Top = parseInt($(div2).css("top")),
      div1Right = div1Left + div1Width,
      div2Right = div2Left + div2Width,
      div1Bottom = div1Top + div1Height,
      div2Bottom = div2Top + div2Height;
    //console.log("zo:"+div2Right);


    if (div2Left < div1Left) {
      console.log("左边超出");
      // div2.css("left","10px");  
      $(div2).css("left", 0 + "px");
      //$(div2).css("width",$("#program").width()+"px");
      //  $(div2).find("#height").val($("#program").height());
    }
    if (div2Top < div1Top) {
      console.log("上边超出");
      //  div2.css("top","10px");  
      $(div2).css("top", 0 + "px");
      // $(div2).css("height",$("#program").height()+"px");
    } else {
      if (pd == 1) {
        var zoomsum = parseInt($("#zoomsum").text());
        if (zoomsum > 0) {
          zoomsum = zoomsum * 2;
          var maxtop = parseInt($("#program").height()) - (parseInt($("#from_" + selectid).find("#high").val()) * zoomsum);

          var topmax = parseInt($("#program_" + selectid).css("top")) + parseInt($("#program_" + selectid).outerHeight());


          if (parseInt(topmax) > parseInt($("#program").height())) {

            $(div2).css("top", maxtop + "px");
          }

        } else {
          var maxtop = parseInt($("#program").height()) - parseInt($("#from_" + selectid).find("#high").val());

          var topmax = parseInt($("#program_" + selectid).css("top")) + parseInt($("#program_" + selectid).outerHeight());


          if (parseInt(topmax) > parseInt($("#program").height())) {

            $(div2).css("top", maxtop + "px");
          }

          console.log("进去了" + selectid);
        }
      }
    }
    if (div2Right > div1Right) {

      var zoomsum = parseInt($("#zoomsum").text());
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        var w1 = parseInt($("#program").width());
        var w2 = parseInt($("#from_" + selectid).find("#width").val()) * zoomsum;

        if (pd == 1) {//碰撞计算
          var maxleft = parseInt(w1) - parseInt(w2);
          console.log("右边超出:" + maxleft);

          $(div2).css("left", maxleft + "px");
          $("#from_" + selectid).find("#left").val(parseInt(maxleft));
          $(div2).css("width", w2 + "px");

          return false;
          //  return false;
          //if(w1==w2||maxleft<8){
          //$(div2).css("left",0+"px"); $("#from_"+selectid).find("#left").val(0);
          //}
        }
        if (parseInt($("#from_" + selectid).find("#left").val()) >= parseInt(sessionStorage.getItem("width"))) {
          var val1 = parseInt(sessionStorage.getItem("width")) - 4;
          $("#from_" + selectid).find("#left").val(4);
          $("#from_" + selectid).find("#width").val(val1);
          $("#program_" + selectid).css("left", "8px");
          $("#program_" + selectid).css("width", (val1 * zoomsum) + "px");
          return false;
        } else {
          console.log("w:" + $("#from_" + selectid).find("#width").val());
          var val1 = parseInt(sessionStorage.getItem("width")) - parseInt($("#from_" + selectid).find("#left").val());

          $("#from_" + selectid).find("#width").val(val1);
          $("#program_" + selectid).css("width", (val1 * zoomsum) + "px");
        }


      } else {
        if (pd == 1) {//碰撞计算
          var maxleft = parseInt($("#program").width()) - parseInt($("#from_" + selectid).find("#width").val());
          $(div2).css("left", maxleft + "px");
          $("#from_" + selectid).find("#left").val(maxleft);
          $(div2).css("width", $("#from_" + selectid).find("#width").val() + "px");

          return false;
        }
        //console.log(123);
        var maxleft = parseInt($("#program").width()) - parseInt($("#from_" + selectid).find("#width").val());
        console.log("右边超出:" + maxleft);
        console.log($("#from_" + selectid).find("#left").val());
        if (parseInt($("#from_" + selectid).find("#left").val()) >= parseInt(sessionStorage.getItem("width"))) {
          var val1 = parseInt(sessionStorage.getItem("width")) - 4;
          $("#from_" + selectid).find("#left").val(4);
          $("#from_" + selectid).find("#width").val(parseInt(val1));
          $("#program_" + selectid).css("left", "4px");
          $("#program_" + selectid).css("width", val1 + "px");
          console.log("qwwq");
          return false;
        } else {
          console.log("qwwq1");
          console.log("w:" + $("#from_" + selectid).find("#width").val());

          var val1 = parseInt(sessionStorage.getItem("width")) - parseInt($("#from_" + selectid).find("#left").val());

          $("#from_" + selectid).find("#width").val(val1);

          $("#program_" + selectid).css("width", val1);
          // $(div2).css("left", maxleft + "px");
          // $("#from_" + selectid).find("#left").val(maxleft);
          // $(div2).css("width", $("#from_" + selectid).find("#width").val() + "px");

        }
        // return false;
        //if(parseInt($("#program").width())==parseInt($("#from_"+selectid).find("#width").val())||maxleft<8){
        //$(div2).css("left",0+"px"); 
        //$("#from_"+selectid).find("#left").val(0);
        //}

      }
    } else {

      var zoomsum = parseInt($("#zoomsum").text());
      // console.log("上边超出"+div2Top);
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        var lef = parseInt($(div2).css("left")) / zoomsum;
        // console.log(lef);
        $("#from_" + selectid).find("#left").val(parseInt(lef));
      } else {

        $("#from_" + selectid).find("#left").val(parseInt($(div2).css("left")));
      }
    }
    if (div2Bottom > div1Bottom) {
      var zoomsum = parseInt($("#zoomsum").text());
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        var h1 = parseInt($("#program").height());
        var h2 = parseInt($("#from_" + selectid).find("#high").val()) * parseInt(zoomsum);

        if (pd == 1) {
          var maxtop = parseInt(h1) - parseInt(h2);
          // console.log("1下边超出:" + maxtop);
          $(div2).css("top", maxtop + "px");
          $("#from_" + selectid).find("#top").val(maxtop);
          $(div2).css("height", h2 + "px");
          console.log(456);
          return false;
        }

        if (parseInt($("#from_" + selectid).find("#top").val()) >= parseInt(sessionStorage.getItem("high"))) {
          var val1 = parseInt(sessionStorage.getItem("high")) - 4;
          $("#from_" + selectid).find("#top").val(4);
          $("#from_" + selectid).find("#high").val(parseInt(val1));
          $("#program_" + selectid).css("top", "8px");
          $("#program_" + selectid).css("height", (val1 * zoomsum) + "px");
          console.log("2下边超出:" + val1);
          return false;
        } else {

          console.log("w:" + $("#from_" + selectid).find("#high").val());
          var val1 = parseInt(sessionStorage.getItem("high")) - parseInt($("#from_" + selectid).find("#top").val());

          $("#from_" + selectid).find("#high").val(parseInt(val1));

          $("#program_" + selectid).css("height", (val1 * zoomsum) + "px");
        }
      } else {

        if (pd == 1) {
          //  var maxtop = parseInt($("#program").height()) - parseInt($("#from_" + selectid).find("#high").val());
          //  console.log("1下边超出:" + maxtop);
          // $(div2).css("top", maxtop+"px");
          // $("#from_" + selectid).find("#top").val(maxtop);
          // $(div2).css("height",$("#from_" + selectid).find("#high").val() + "px");

          var maxtop = parseInt($("#program").height()) - parseInt($("#from_" + selectid).find("#high").val());
          $(div2).css("top", maxtop + "px");
          $("#from_" + selectid).find("#top").val(maxtop);
          $(div2).css("height", $("#from_" + selectid).find("#high").val() + "px");

          var topmax = parseInt($("#from_" + selectid).find("#high").val()) + parseInt($("#from_" + selectid).find("#top").val());
          if (parseInt(topmax) > parseInt($("#program").height())) {


            $(div2).css("top", maxtop + "px");
          }

          // 
          return false;
        }

        var maxtop = parseInt($("#program").height()) - parseInt($("#from_" + selectid).find("#high").val());
        if (parseInt($("#from_" + selectid).find("#top").val()) >= parseInt(sessionStorage.getItem("high"))) {
          console.log("2下边超出:" + maxtop);
          var val1 = parseInt(sessionStorage.getItem("high")) - 4;
          $("#from_" + selectid).find("#top").val(4);
          $("#from_" + selectid).find("#high").val(parseInt(val1));
          $("#program_" + selectid).css("top", "4px");
          $("#program_" + selectid).css("height", val1 + "px");
          return false;
        } else {

          console.log("w:" + $("#from_" + selectid).find("#high").val());
          var val1 = parseInt(sessionStorage.getItem("high")) - parseInt($("#from_" + selectid).find("#top").val());

          $("#from_" + selectid).find("#high").val(parseInt(val1));

          $("#program_" + selectid).css("height", val1);
        }

      }
    } else {
      var zoomsum = parseInt($("#zoomsum").text());
      if (zoomsum > 0) {
        zoomsum = zoomsum * 2;
        var top = parseInt($(div2).css("top")) / zoomsum;
        $("#from_" + selectid).find("#top").val(parseInt(top));
      } else {
        //var top=parseInt($(div2).css("top"));

        $("#from_" + selectid).find("#top").val(parseInt($(div2).css("top")));

        // $("#from_"+selectid).find("#top").val(parseInt(top));
      }
    }
    //$("#from_"+selectid).find("#left").val(div2Left);
    //$("#from_"+selectid).find("#top").val(div2Top);
    //console.log("qq");
    //xywhinputval();
  } catch (ex) {
    console.log("zo:" + ex);
  }
  //画布

 textcanvas(selectid, pd);


}
window.xc = function (val) {



  if (val == 0) {
    $("#from_" + selectid).find("#Dazzle").html("<option value='0'>无效果</option>");
    $("#from_" + selectid).find("#Dazzle").parent().css("margin-left", "");
    $("#from_" + selectid).find("#fontcolor").parent().show();
    //  $("#from_"+selectid).find("#typefaceval").parent().show();
    $("#from_" + selectid).find("#alignment").parent().hide();
    // $("#from_"+selectid).find("#typefaceval").val("");
    $("#from_" + selectid).find("#alignment").val("0");
    $("#program_" + selectid).find("div").css("font-family", "");
    $("#program_" + selectid).css("display", "");
    $("#program_" + selectid).css("align-items", "");
    // $("#from_"+selectid).find("#typefaceval").parent().css("margin-left","")

    // $("#from_"+selectid).find("#randomFontColor").parent().show();

  } else {
    $("#from_" + selectid).find("#Dazzle").html("<option value='" + val + "'>炫彩效果" + val + "</option>");
    $("#from_" + selectid).find("#Dazzle").parent().css("margin-left", "");
    $("#from_" + selectid).find("#typefaceval").val("4");
    //隐藏颜色
    $("#from_" + selectid).find("#fontcolor").parent().hide();
    //  $("#from_" + selectid).find("#typefaceval").parent().hide();
    $("#from_" + selectid).find("#alignment").val("0");
    //$("#from_"+selectid).find("#typefaceval").parent().hide();
    $("#from_" + selectid).find("#alignment").parent().hide();
    $("#program_" + selectid).find("div").css("font-family", "");
    $("#program_" + selectid).css("display", "");
    $("#program_" + selectid).css("align-items", "");
    $("#from_" + selectid).find("#randomFontColor").val("0");
    $("#from_" + selectid).find("#randomFontColor").parent().hide();
  }
  $(".close").click();
}


//gif尺寸小于分区
window.gifwg = function (index) {
  if ($("#material #" + index + " a").text().trim() == "动画") {
    var gifwidepth = $("#gifwidepth").val().split('*'), width = 0, height = 0;
    width = zoomsum == 0 ? parseInt(gifwidepth[0]) : (parseInt(gifwidepth[0]) * (zoomsum * 2));
    height = zoomsum == 0 ? parseInt(gifwidepth[1]) : (parseInt(gifwidepth[1]) * (zoomsum * 2));
    $("#program_" + index).find("img").width(width);
    $("#program_" + index).find("img").height(height);
    $("#program_" + index).find("img").css({
      "position": "absolute", "margin": "auto", "top": "0",
      "right": "0", "bottom": "0", "left": "0", "z-index": "1"
    });
  }


}


//进入速度正则
window.inspeedOnkeup = function (th) {
  var speedlabel = $(th).parent().prev().text().toString();
  speedlabel = speedlabel.substring(0, 3);
  // console.log("值:"+speedlabel.trim());
  if (speedlabel.trim() == "gif") {
    th.value = th.value.replace(/[^\-0-9]/g, '');
  } else {

    th.value = th.value.replace(/\D/g, '');

  }
};



//时段个数选择
window.timeChange = function () {
  for (var i = 1; i <= 8; i++) {
    //先全部禁用
    $("#liveStart" + i).find("input").attr("disabled", true);
    $("#liveStart" + i).css("color", "gainsboro");
    $("#liveEnd" + i).find("input").attr("disabled", true);
    $("#liveEnd" + i).css("color", "gainsboro");
  }
  for (var i = 1; i <= parseInt($("#liveCount").val()); i++) {
    //根据选择个数来设置

    $("#liveStart" + i).find("input").removeAttr("disabled");
    $("#liveStart" + i).css("color", "");
    $("#liveEnd" + i).find("input").removeAttr("disabled");
    $("#liveEnd" + i).css("color", "");

  }
}




//变量
window.textcanvas = function (index, pd) {
  if ($("#material #" + index + " a").text().trim() == "文本") {
    var textcanvas = "<canvas id=textcanvas width=" + (parseInt($("#program_" + index).outerWidth())) + " height=" + $("#program_" + index).outerHeight() + " class=textcanvas></canvas>";
    if (pd != 1) {
      $("#program_" + index).html(textcanvas);
    }
   /// console.log("pid进来"+pd)
    var mycanvas = $("#program_" + index).find("#textcanvas")[0];
    var context = mycanvas.getContext("2d");
   
    context.clearRect(0, 0, mycanvas.width, mycanvas.height);
    var size = $('#from_' + index).find("#fontsizeadd").find("option:selected").text();
    var fontSize = "";
    //有没有放大
    var zoomsum = parseInt($("#zoomsum").text());
    if (zoomsum > 0) {
      zoomsum = zoomsum * 2;
      fontSize = parseInt(size.split("*")[0]) * zoomsum;
    } else {
      fontSize = parseInt(size.split("*")[0]);
    }
    var fontSizey = fontSize / 2;
    fontSizey = 0 - fontSizey;
    info = $("#from_" + index).find("#fosizeval").val();
    //  console.log("index:"+index);
    if (pd != 1) {

      new ZResize({
        stage: "#program", //舞台 
        item: '#program_' + index, //可缩放的类名 
      });
    }
    try {
      //电脑字体
      if ($("#from_" + index).find("#texttype").val() == "1") {
        //console.log("电脑字体:"+pd);
        Canvasfont(pd);
      } else {
        drawText(context, info, 0, fontSizey, parseInt($("#program_" + index).outerWidth()), fontSize, $("#from_" + index).find("#fontcolor").val());
      }
    } catch (ex) {
      this.alert(ex);
    }
  }

}
//canvas对象  t文本数据  x默认0 y传文字的负高度    w宽度 fontsize字体大小 color文字颜色
window.drawText = function (context, t, x, y, w, fontsize, color) {
  var chr = t.split("");
  var temp = "";
  var row = [];
  context.font = fontsize + "px monospace";
  context.fillStyle = color;
  context.textBaseline = "middle";
  var c = 0;
  for (var a = 0; a < chr.length; a++) {
    var is = true;
    if (context.measureText(temp).width < w && context.measureText(temp + (chr[a])).width <= w) {
      //回车换行
      if (chr[a] == "\n") {
        is = false;
        row.push(temp); temp = "";
        chr[a] = "";
      } else {
        temp += chr[a];
      }
    }
    else if (is) {
      //回车换行
      if (chr[a] == "\n") {
        row.push(temp); temp = "";
        chr[a] = "";
      } else {
        row.push(temp);
        temp = chr[a];
      }
    }
  }
  row.push(temp);
  for (var b = 0; b < row.length; b++) {
    row[b] = row[b].replace(/\n/g, "");
    context.fillText(row[b], x, y + (b + 1) * fontsize);//字体计算换行
    // context.fillText(row[b], 40,100);//字体计算换行
  }
}

//电脑字体
var PROGRAM_FONT = { "1": "\u9ed1\u4f53", "2": "\u5b8b\u4f53", "3": "\u6977\u4f53", "4": "\u96b6\u4e66", "5": "\u5fae\u8f6f\u96c5\u9ed1" }; // 广告字体
var PROGRAM_FONT_CSS = { 1: 'SimHei', 2: 'SimSun', 3: 'KaiTi', 4: 'LiSu', 5: 'YaHei' };
var RGBCOLOR = { "255": "#ff0000", "65280": "#28ea28", "65535": "#ffff00", "16711680": "#2363f7", "16711935": "#d704ef", "16776960": "#0ef2f5", "16777215": "#ffffff" };
var fontSize = 32; var bordercolor = 0; var pageval = 1;
var parameter = [0.5, 2, 4, 100, 0];//参数
window.init = function () {
  var html = "";
  for (k in PROGRAM_FONT) { html += '<li><a val="' + k + '"><span style="font-family:' + PROGRAM_FONT_CSS[k] + '">' + PROGRAM_FONT[k] + '</span></a></li>'; } //字体options
  $("#from_" + selectid).find('.drop_font2').html(html);
  var iteminfo = { "font": 2 };
  updateTextArea($("#from_" + selectid).find("#text_pic_form"), iteminfo);
  $("#from_" + selectid).find(".drop_font2 li").click(function () {
    //console.log($(this).find("span").attr("style"));
    $("#from_" + selectid).find(".text-family").html("<span style=" + $(this).find("span").attr("style") + ">" + $(this).find("span").text() + "</span>");
  });
  //选择颜色
  $("#from_" + selectid).find(".drop_color2 li").click(function () {
    // alert(123);
    $("#from_" + selectid).find(".text-color").find("button:eq(0)").html("<span class=" + $(this).find("span").attr("class") + "></span>" + $(this).find("a").text());
  });
  //选择字号
  $("#from_" + selectid).find(".drop_fontsize2 li").click(function () {
    fontSize = parseFloat($(this).find("a").attr("val")) * 2;
    $("#from_" + selectid).find(".text-size").find("button:eq(0)").html($(this).find("a").text());
    $("#from_" + selectid).find(".text-size").find("button:eq(0)").attr("val", $(this).find("a").attr("val"));
    Canvasfont();
  });
  //输入
  $("#from_" + selectid).find('#editor').keyup(function () {
    //  if($(this).html()=="<br>"){$(this).html("");  return;};
    $("#from_" + selectid).find(".text-length").find('span').text("已输入" + $(this).html().replace(/&nbsp;/g, " ").replace(/<[^>]+>/g, "").length + "字");
    if ($(this).html().length == 0) { //清除所有文字时，重置属性
      $("#from_" + selectid).find("#editor").html("<font  color='#ff0000' face='SimSun'></font>");
      return;
    }
    Canvasfont();
  });
  //颜色
  $("#from_" + selectid).find(".drop_color2").on('mousedown', 'a', function () {
    $("#from_" + selectid).find(".text-family").find("button:eq(0)").html("<span class=" + $(this).find("span").attr("class") + "></span>" + $(this).text());
    document.execCommand("forecolor", false, RGBCOLOR[$(this).attr("val")]);
    Canvasfont();
  });
  //字体
  $("#from_" + selectid).find(".drop_font2").on('mousedown', 'a', function () {
    // $("#from_" + selectid).find(".text-color").find("button:eq(0)").html("<span class="+$(this).find("span").attr("class")+"></span>"+$(this).text()); 
    document.execCommand("fontName", false, PROGRAM_FONT_CSS[$(this).attr("val")]);
    Canvasfont();
  });
}
//替换html数据
window.tokenization = function (_playitem) {
  //对于IE,而chrome和firefox用<b>,对于IE和firefox换行用<br>newline,而chrome用<div>newline</div>
  console.log(_playitem)
  var i = 0, tagpart = false, tag = "", txt_obj = [];
  var face = ["SimSun"];
  //  console.log(face);
  var color = ["#ff0000"];
  var fontsize = [fontSize];

  var value = _playitem.replace(/<br>/g, "\n").replace(/&nbsp;/g, " ");
  var str_len = value.length;
  for (i; i < str_len; i++) {
    if (value[i] == "<") {
      tagpart = true;
      tag = "";
    } else if (value[i] == ">") {
      tagpart = false;
      if (txt_obj.length > 0 && /^div$/.test(tag)) {
        if (txt_obj[txt_obj.length - 1].length > 1) txt_obj.push(["\n"]);
      } else if (/^\/font$/.test(tag)) {
        face.pop();
        color.pop();
        fontsize.pop();
      } else {
        if (/face="([^\s]*)"/.test(tag)) {
          face.push(RegExp.$1);
        } else {
          face.push(face[face.length - 1]);
        }
        if (/color="([^\s]{1,7})"/.test(tag)) {
          color.push(RegExp.$1);
        } else {
          color.push(color[color.length - 1]);
        }
        if (/(\d*)px/.test(tag)) {
          fontsize.push(RegExp.$1);
        } else {
          fontsize.push(fontsize[fontsize.length - 1]);
        }
      }
    } else if (tagpart) {
      tag += value[i];
    } else {
      txt_obj.push([value[i], face[face.length - 1], color[color.length - 1], fontsize[fontsize.length - 1], false]);
    }

  }
  if (txt_obj.length > 0 && txt_obj[(txt_obj.length - 1)][0] == '\n') txt_obj.splice((txt_obj.length - 1), 1);
  return txt_obj;
}
var totalht = 0;//总高度
window.renderTextpic = function (ctx, type) {
  var text = tokenization($("#from_" + selectid).find("#editor").html());
  //有没有放大
  var zoomsum = type == 1 ? parseInt($("#zoomsum").text()) : 0;
  var width = 0;
  if (type == 1) {
    width = parseInt($("#program_" + selectid).outerWidth());
  } else {
    if (parseInt($("#zoomsum").text()) > 0) {
      width = (parseInt($("#program_" + selectid).outerWidth()) / ((parseInt($("#zoomsum").text()) * parameter[1])));
    }
  }
  var textsize = parseInt($("#from_" + selectid).find(".text-size button:eq(0)").text()); totalht = textsize;
  if (zoomsum > 0) { zoomsum = zoomsum * parameter[1]; textsize = textsize * zoomsum; totalht = (textsize / parameter[1]); }
  var textsizemax = parseInt(width / textsize) + 1, breadht = 0, breadhty = parseInt($("#from_" + selectid).find(".text-size button:eq(0)").text());
  var breadth = 0;
  for (var i = 0; i < text.length; i++) {
    ctx.font = textsize + "px " + text[i][1];
    ctx.fillStyle = text[i][2];
    ctx.textBaseline = "middle";
    var chr = text[i][0].split("");
    for (var j = 0; j < chr.length; j++) {
      var regNumber = /\d+/, regString = /[a-zA-Z]+/, sinogram = true;//验证0-9的任意数字最少出现1次，验证大小写26个字母任意字母最少出现1次。
      if (regNumber.test(chr[j]) || regString.test(chr[j])) {
        sinogram = false;
        breadth += textsize / parameter[1];
        breadht += parameter[0];
      } else {
        breadth += textsize;
        breadht++;
      }
      //换行
      if (Math.round(breadht) == textsizemax || chr[j] == "\n") {
        breadht = parameter[4];
        breadth = chr[j] != "\n" ? textsize : parameter[4];
        breadhty += (textsize + parameter[2]);
        totalht += zoomsum > 0 ? ((textsize / parameter[1]) + parameter[2]) : (textsize + parameter[2]);
        breadth = !sinogram ? (textsize / parameter[1]) : breadth;
      }
      //填充文字
      ctx.fillText(chr[j], sinogram == true ? (breadth - textsize) : (breadth - (textsize / parameter[1])), breadhty);
    }
  }
};
//构建电脑字体
window.Canvasfont = function (pd) {
  var textcanvas = "<canvas id=textcanvas width=" + (parseInt($("#program_" + selectid).outerWidth())) + " height=" + $("#program_" + selectid).outerHeight() + " class=textcanvas></canvas>";
  if (pd != 1) {
    $("#program_" + selectid).html(textcanvas);
  }
  if (pd != 1) {
    new ZResize({
      stage: "#program", //舞台 
      item: '#program_' + selectid, //可缩放的类名 
    });
  }
  var mycanvas = $("#program_" + selectid).find("#textcanvas")[0];
  var context = mycanvas.getContext("2d");
  context.clearRect(0, 0, mycanvas.width, mycanvas.height);
  renderTextpic(context, 1);
  var mycanvasadd = $("#from_" + selectid).find("#mycanvasadd")[0];
  mycanvasadd.width = parseInt($("#zoomsum").text()) > 0 ? (parseInt($("#program_" + selectid).outerWidth()) / 2) : (parseInt($("#program_" + selectid).outerWidth()));
  mycanvasadd.height = (totalht) + parameter[3];
  var contextadd = mycanvasadd.getContext("2d");
  contextadd.clearRect(0, 0, mycanvasadd.width, mycanvasadd.height);
  contextadd.fillStyle = "#000000";
  contextadd.fillRect(0, 0, mycanvasadd.width, mycanvasadd.height);
  renderTextpic(contextadd, 0);
  var base64 = mycanvasadd.toDataURL('image/png');
  console.log(base64);
  $("#from_" + selectid).find("#imgDataURL").val(base64);
  console.log("totalht:" + totalht);
  // renderTextpic(context,parseFloat($("#from_" + selectid).find(".text-size button:eq(0)").attr("val"))*2,bordercolor,$("#from_" + selectid).find("#alignment").val());
}
window.updateTextArea = function (_formelem, _iteminfo) {
  if (_iteminfo["font"] != undefined) {
    $("#from_" + selectid).find(".text-family").html('<span style="font-family:' + PROGRAM_FONT_CSS[_iteminfo["font"]] + '">' + PROGRAM_FONT[_iteminfo["font"]] + '</span>');
  }
};




